Example #1
0
        private async Task <bool> IsReady(AzureHttpClient client, string sitename)
        {
            bool isReady = false;

            for (int i = 0; i < ATTEMPTS && !isReady; i++)
            {
                FunctionStatusWrapper statusWrapper = await client.RequestAzure <FunctionStatusWrapper>(HttpMethod.Get, $"/providers/Microsoft.Web/sites/{sitename}/deployments", "2016-08-01");

                if (statusWrapper != null && !statusWrapper.Value.IsNullOrEmpty())
                {
                    bool hasFinishedDeployment = true;

                    for (int j = 0; j < statusWrapper.Value.Count && hasFinishedDeployment; j++)
                    {
                        FunctionStatus status = statusWrapper.Value[j];

                        hasFinishedDeployment = status != null && status.Properties != null && !string.IsNullOrEmpty(status.Properties.LogUrl);

                        if (hasFinishedDeployment)
                        {
                            List <FunctionStatusLog> logs = await client.Request <List <FunctionStatusLog> >(HttpMethod.Get, status.Properties.LogUrl);

                            hasFinishedDeployment = !logs.IsNullOrEmpty();

                            if (hasFinishedDeployment)
                            {
                                bool isDeployed = false;

                                for (int k = 0; k < logs.Count && !isDeployed; k++)
                                {
                                    isDeployed = logs[k].Message.Contains(SUCCESS);
                                }

                                hasFinishedDeployment = isDeployed && status.Properties.Active && status.Properties.Complete &&
                                                        status.Properties.EndTime != null && status.Properties.Status == STATUS;
                            }
                        }
                    }

                    if (hasFinishedDeployment)
                    {
                        FunctionWrapper functionWrapper = await client.RequestAzure <FunctionWrapper>(HttpMethod.Get, $"/providers/Microsoft.Web/sites/{sitename}/functions", "2016-08-01");

                        if (functionWrapper != null && !functionWrapper.Value.IsNullOrEmpty())
                        {
                            bool areFunctionsReady = true;

                            for (int j = 0; j < functionWrapper.Value.Count && areFunctionsReady; j++)
                            {
                                Function function = functionWrapper.Value[j];

                                areFunctionsReady = function != null && function.Properties != null && function.Properties.Config != null && !function.Properties.Config.Disabled;
                            }

                            isReady = areFunctionsReady;
                        }
                    }
                }

                if (!isReady)
                {
                    await Task.Delay(WAIT);
                }
            }

            return(isReady);
        }