Esempio n. 1
0
 public RuleWrapper(AggregatorConfiguration configuration, IAggregatorLogger logger, string ruleName, string functionDirectory)
 {
     this.configuration     = configuration;
     this.logger            = logger;
     this.ruleName          = ruleName;
     this.functionDirectory = functionDirectory;
 }
Esempio n. 2
0
 public EngineContext(IClientsContext clients, Guid projectId, string projectName, IAggregatorLogger logger)
 {
     Clients     = clients;
     Logger      = logger;
     Tracker     = new Tracker();
     ProjectId   = projectId;
     ProjectName = projectName;
 }
Esempio n. 3
0
 public EngineContext(WorkItemTrackingHttpClient client, Guid projectId, string projectName, IAggregatorLogger logger)
 {
     Client      = client;
     Logger      = logger;
     Tracker     = new Tracker();
     ProjectId   = projectId;
     ProjectName = projectName;
 }
Esempio n. 4
0
        internal DirectivesParser(IAggregatorLogger logger, string[] ruleCode)
        {
            this.ruleCode = ruleCode;
            this.logger   = logger;

            //defaults
            Language = Languages.Csharp;
        }
        public WorkItemStoreTests()
        {
            logger = Substitute.For <IAggregatorLogger>();

            clientsContext = new TestClientsContext();

            witClient = clientsContext.WitClient;
            witClient.ExecuteBatchRequest(default).ReturnsForAnyArgs(info => new List <WitBatchResponse>());
Esempio n. 6
0
 public EngineContext(WorkItemTrackingHttpClientBase client, Guid projectId, string projectName, string personalAccessToken, IAggregatorLogger logger)
 {
     Client              = client;
     Logger              = logger;
     Tracker             = new Tracker();
     ProjectId           = projectId;
     ProjectName         = projectName;
     PersonalAccessToken = personalAccessToken;
 }
Esempio n. 7
0
        internal DirectivesParser(IAggregatorLogger logger, string[] ruleCode)
        {
            this.ruleCode = ruleCode;
            this.logger   = logger;

            //defaults
            Language   = Languages.Csharp;
            References = references;
            Imports    = imports;
        }
Esempio n. 8
0
        public RuleEngine(IAggregatorLogger logger, string[] ruleCode, SaveMode mode, bool dryRun)
        {
            State = EngineState.Unknown;

            this.logger   = logger;
            this.saveMode = mode;
            this.DryRun   = dryRun;

            var directives = new DirectivesParser(logger, ruleCode);

            if (!directives.Parse())
            {
                State = EngineState.Error;
                return;
            }

            if (directives.Language == DirectivesParser.Languages.Csharp)
            {
                var types = new List <Type>()
                {
                    typeof(object),
                    typeof(System.Linq.Enumerable),
                    typeof(System.Collections.Generic.CollectionExtensions),
                    typeof(Microsoft.VisualStudio.Services.WebApi.IdentityRef)
                };
                var references = types.ConvertAll(t => t.Assembly).Distinct();

                var scriptOptions = ScriptOptions.Default
                                    .WithEmitDebugInformation(true)
                                    .WithReferences(references)
                                    // Add namespaces
                                    .WithImports(
                    "System",
                    "System.Linq",
                    "System.Collections.Generic",
                    "Microsoft.VisualStudio.Services.WebApi"
                    );

                this.roslynScript = CSharpScript.Create <string>(
                    code: directives.GetRuleCode(),
                    options: scriptOptions,
                    globalsType: typeof(Globals));
            }
            else
            {
                logger.WriteError($"Cannot execute rule: language is not supported.");
                State = EngineState.Error;
            }
        }
Esempio n. 9
0
        public RuleEngine(IAggregatorLogger logger, string[] ruleCode, SaveMode mode, bool dryRun)
        {
            State = EngineState.Unknown;

            this.logger   = logger;
            this.saveMode = mode;
            this.DryRun   = dryRun;

            var directives = new DirectivesParser(logger, ruleCode);

            if (!directives.Parse())
            {
                State = EngineState.Error;
                return;
            }

            if (directives.Language == DirectivesParser.Languages.Csharp)
            {
                var references = LoadReferences(directives);
                var imports    = GetImports(directives);

                var scriptOptions = ScriptOptions.Default
                                    .WithEmitDebugInformation(true)
                                    .WithReferences(references)
                                    // Add namespaces
                                    .WithImports(imports)
                ;

                this.roslynScript = CSharpScript.Create <string>(
                    code: directives.GetRuleCode(),
                    options: scriptOptions,
                    globalsType: typeof(Globals));
            }
            else
            {
                logger.WriteError($"Cannot execute rule: language is not supported.");
                State = EngineState.Error;
            }
        }
Esempio n. 10
0
 protected RuleEngineBase(IAggregatorLogger logger, SaveMode saveMode, bool dryRun)
 {
     this.logger   = logger;
     this.saveMode = saveMode;
     this.dryRun   = dryRun;
 }
Esempio n. 11
0
        /// <summary>
        /// Grab directives
        /// </summary>
        public static (IPreprocessedRule preprocessedRule, bool parseSuccess) Read(string[] ruleCode, IAggregatorLogger logger = default)
        {
            var parsingIssues = false;

            void FailParsingWithMessage(string message)
            {
                logger?.WriteWarning(message);
                parsingIssues = true;
            }

            var directiveLineIndex = 0;
            var preprocessedRule   = new PreprocessedRule()
            {
                Language = RuleLanguage.Csharp
            };

            while (directiveLineIndex < ruleCode.Length &&
                   ruleCode[directiveLineIndex].Length > 0 &&
                   ruleCode[directiveLineIndex][0] == '.')
            {
                string directive = ruleCode[directiveLineIndex].Substring(1);
                var    parts     = directive.Split('=');

                switch (parts[0].ToLowerInvariant())
                {
                case "lang":
                case "language":
                    if (parts.Length < 2)
                    {
                        FailParsingWithMessage($"Invalid language directive {directive}");
                    }
                    else
                    {
                        switch (parts[1].ToUpperInvariant())
                        {
                        case "C#":
                        case "CS":
                        case "CSHARP":
                            preprocessedRule.Language = RuleLanguage.Csharp;
                            break;

                        default:
                        {
                            FailParsingWithMessage($"Unrecognized language {parts[1]}");
                            preprocessedRule.Language = RuleLanguage.Unknown;
                            break;
                        }
                        }
                    }
                    break;

                case "r":
                case "ref":
                case "reference":
                    if (parts.Length < 2)
                    {
                        FailParsingWithMessage($"Invalid reference directive {directive}");
                    }
                    else
                    {
                        preprocessedRule.References.Add(parts[1]);
                    }
                    break;

                case "import":
                case "imports":
                case "namespace":
                    if (parts.Length < 2)
                    {
                        FailParsingWithMessage($"Invalid import directive {directive}");
                    }
                    else
                    {
                        preprocessedRule.Imports.Add(parts[1]);
                    }
                    break;

                case "impersonate":
                    if (parts.Length < 2)
                    {
                        FailParsingWithMessage($"Invalid impersonate directive {directive}");
                    }
                    else
                    {
                        preprocessedRule.Impersonate = string.Equals("onBehalfOfInitiator", parts[1].TrimEnd(), StringComparison.OrdinalIgnoreCase);
                    }
                    break;

                default:
                {
                    FailParsingWithMessage($"Unrecognized directive {directive}");
                    break;
                }
                }//switch

                // this keep the same number of lines
                preprocessedRule.RuleCode.Add($"// {directive}");

                directiveLineIndex++;
            }//while

            preprocessedRule.FirstCodeLine = directiveLineIndex;

            preprocessedRule.RuleCode.AddRange(ruleCode.Skip(preprocessedRule.FirstCodeLine));

            var parseSuccessful = !parsingIssues;

            return(preprocessedRule, parseSuccessful);
        }
Esempio n. 12
0
        /// <summary>
        /// Grab directives
        /// </summary>
        public static (IPreprocessedRule preprocessedRule, bool parseSuccess) Read(string[] ruleCode, IAggregatorLogger logger = default)
        {
            var me     = new RuleFileParser(logger);
            var result = me.Parse(ruleCode);

            if (result.parseSuccess)
            {
                result.parseSuccess = me.Validate(result.preprocessedRule);
            }
            return(result);
        }
Esempio n. 13
0
 public ScriptedRuleWrapper(string ruleName, IPreprocessedRule preprocessedRule, IAggregatorLogger logger) : this(ruleName, logger)
 {
     Initialize(preprocessedRule);
 }
Esempio n. 14
0
 public RuleExecutor(IAggregatorLogger logger, IAggregatorConfiguration configuration)
 {
     this.configuration = configuration;
     this.logger        = logger;
 }
 public AspNetRuleProvider(ForwarderLogger logger, IConfiguration configuration)
 {
     this._logger        = logger;
     this._configuration = configuration;
 }
Esempio n. 16
0
 public RuleEngine(IAggregatorLogger logger, SaveMode saveMode, bool dryRun) : base(logger, saveMode, dryRun)
 {
 }
Esempio n. 17
0
 private ScriptedRuleWrapper(string ruleName, IAggregatorLogger logger)
 {
     _logger = logger;
     Name    = ruleName;
 }
Esempio n. 18
0
 public AzureFunctionRuleProvider(IAggregatorLogger logger, string functionDirectory)
 {
     _logger    = logger;
     _rulesPath = functionDirectory;
 }
Esempio n. 19
0
        public static async Task <(IPreprocessedRule preprocessedRule, bool result)> ReadFile(string ruleFilePath, IAggregatorLogger logger, CancellationToken cancellationToken = default)
        {
            var content = await ReadAllLinesAsync(ruleFilePath, cancellationToken);

            return(Read(content, logger));
        }
Esempio n. 20
0
 public static void Reset(IAggregatorLogger instance)
 {
     agregatorLogger.Reset(instance);
 }
Esempio n. 21
0
 public RuleFileParser(IAggregatorLogger logger)
 {
     this.logger = logger;
 }
Esempio n. 22
0
		public static void Reset(IAggregatorLogger instance)
		{
			agregatorLogger.Reset(instance);
		}