/// <summary>
        /// Creates a new authenticated instance of the <see cref="LogicAppClient"/>.
        /// </summary>
        /// <param name="resourceGroup">The resource group where the logic app is located.</param>
        /// <param name="logicAppName">The name of the logic app resource running in Azure.</param>
        /// <param name="authentication">The authentication mechanism to authenticate this client.</param>
        /// <param name="logger">The instance to write diagnostic trace messages while interacting with the logic app.</param>
        /// <returns>
        ///     An authenticated client capable of interacting with the logic app resource running in Azure.
        /// </returns>
        public static async Task<LogicAppClient> CreateAsync(
            string resourceGroup,
            string logicAppName,
            LogicAppAuthentication authentication,
            ILogger logger)
        {
            Guard.NotNullOrEmpty(resourceGroup, nameof(resourceGroup));
            Guard.NotNullOrEmpty(logicAppName, nameof(logicAppName));
            Guard.NotNull(authentication, nameof(authentication));

            LogicManagementClient managementClient = await authentication.AuthenticateAsync();
            logger = logger ?? NullLogger.Instance;
            return new LogicAppClient(resourceGroup, logicAppName, managementClient, logger);
        }
示例#2
0
        private async Task <IEnumerable <LogicAppRun> > GetLogicAppRunsAsync()
        {
            using (LogicManagementClient managementClient = await _authentication.AuthenticateAsync())
            {
                var odataQuery = new ODataQuery <WorkflowRunFilter>
                {
                    Filter = $"StartTime ge {_startTime.UtcDateTime:O} and Status ne 'Running'"
                };

                if (_hasCorrelationId)
                {
                    odataQuery.Filter += $" and ClientTrackingId eq '{_correlationId}'";
                }

                _logger.LogTrace(
                    "Query logic app runs for '{LogicAppName}' in resource group '{ResourceGroup}': {Query}", _logicAppName, _resourceGroup, odataQuery.Filter);

                IPage <WorkflowRun> workFlowRuns =
                    await managementClient.WorkflowRuns.ListAsync(_resourceGroup, _logicAppName, odataQuery);

                _logger.LogTrace("Query returned {WorkFlowRunCount} workflow runs", workFlowRuns.Count());

                var logicAppRuns = new Collection <LogicAppRun>();
                foreach (WorkflowRun workFlowRun in workFlowRuns)
                {
                    IEnumerable <LogicAppAction> actions =
                        await FindLogicAppRunActionsAsync(managementClient, workFlowRun.Name);

                    if (_trackingProperties.Count > 0 && actions.Any(action => HasTrackedProperty(action.TrackedProperties)) ||
                        _trackingProperties.Count <= 0)
                    {
                        var logicAppRun = LogicAppConverter.ToLogicAppRun(workFlowRun, actions);
                        logicAppRuns.Add(logicAppRun);
                    }
                }

                _logger.LogTrace("Query resulted in {LogicAppRunCount} logic app runs", logicAppRuns.Count);
                return(logicAppRuns.AsEnumerable());
            }
        }