public static void Initialize(TestContext context)
        {
            account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            var surveyStorage = new AzureBlobContainer <Survey>(account, SurveyContainer);

            surveyStorage.EnsureExistsAsync().Wait();
        }
Ejemplo n.º 2
0
        private async Task AppendSurveyAnswerIdToSurveyAnswerListAsync(string slugName, string surveyAnswerId)
        {
            var SurveyAnswersListContainerName = "surveyanswerslist";

            if (string.IsNullOrWhiteSpace(slugName))
            {
                throw new ArgumentException($"{nameof(slugName)} cannot be null, empty, or only whitespace");
            }

            if (string.IsNullOrWhiteSpace(surveyAnswerId))
            {
                throw new ArgumentException($"{nameof(surveyAnswerId)} cannot be null, empty, or only whitespace");
            }

            var answerListContainer = new AzureBlobContainer <List <string> >(
                ServiceFabricConfiguration.GetCloudStorageAccount(), SurveyAnswersListContainerName);

            try
            {
                await SaveAsync(answerListContainer, slugName, surveyAnswerId);
            }
            catch (StorageException ex)
            {
                if (ex.Message.Contains("404"))
                {
                    await answerListContainer.EnsureExistsAsync();
                    await SaveAsync(answerListContainer, slugName, surveyAnswerId);
                }
                else
                {
                    throw ex;
                }
            }
        }
        public static void Initialize(TestContext context)
        {
            account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            var azureBlobContainer = new AzureBlobContainer <string>(
                account,
                AzureBlobTestContainer);

            azureBlobContainer.EnsureExistsAsync().Wait();
        }
 public void TestInitialize()
 {
     target = new SurveyManagementService(null,
                                          (tableName) => {
         var azureTable = new AzureTable <Models.SurveyInformationRow>(account, tableName);
         azureTable.EnsureExistsAsync().Wait();
         return(azureTable);
     },
                                          (containerName) => {
         azureBlobContainer = new AzureBlobContainer <Models.Survey>(
             account,
             containerName);
         azureBlobContainer.EnsureExistsAsync().Wait();
         return(azureBlobContainer);
     });
 }
Ejemplo n.º 5
0
        public void TestInitialize()
        {
            target = new SurveyAnswerService(null,
                                             (containerName) => {
                azureBlobSurveyAnswerContainer = new AzureBlobContainer <Models.SurveyAnswer>(
                    account,
                    containerName);
                azureBlobSurveyAnswerContainer.EnsureExistsAsync().Wait();
                return(azureBlobSurveyAnswerContainer);
            },

                                             (containerName) => {
                azureBlogStringListContainer = new AzureBlobContainer <List <string> >(
                    account,
                    containerName);
                azureBlogStringListContainer.EnsureExistsAsync().Wait();
                return(azureBlogStringListContainer);
            },

                                             new Mock <ISurveyAnalysisService>().Object);
        }
Ejemplo n.º 6
0
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            int  batchSize = 100;
            long delayMs   = 20;

            surveyQueue = await this.StateManager.GetOrAddAsync <IReliableConcurrentQueue <ClientModels.SurveyAnswer> >("surveyQueue");

            ISurveyAnalysisService surveyAnalysisService = new Tailspin.SurveyAnalysisService.Client.SurveyAnalysisService();

            List <ClientModels.SurveyAnswer> processItems = new List <ClientModels.SurveyAnswer>();

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    using (var tx = this.StateManager.CreateTransaction())
                    {
                        ConditionalValue <ClientModels.SurveyAnswer> ret;

                        for (int i = 0; i < batchSize; ++i)
                        {
                            ret = await surveyQueue.TryDequeueAsync(tx, cancellationToken);

                            if (ret.HasValue)
                            {
                                processItems.Add(ret.Value.DeepCopy());
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (processItems.Count > 0)
                        {
                            foreach (var sa in processItems)
                            {
                                var model = sa.ToSurveyAnswer();
                                model.CreatedOn = DateTime.UtcNow;

                                var container = new AzureBlobContainer <ApiModels.SurveyAnswer>(
                                    ServiceFabricConfiguration.GetCloudStorageAccount(),
                                    $"{model.SlugName}-answers");

                                try
                                {
                                    await container.SaveAsync(model.Id, model);
                                }
                                catch (StorageException ex)
                                {
                                    if (ex.Message.Contains("404"))
                                    {
                                        await container.EnsureExistsAsync();

                                        await container.SaveAsync(model.Id, model);
                                    }
                                    else
                                    {
                                        throw ex;
                                    }
                                }

                                await this.AppendSurveyAnswerIdToSurveyAnswerListAsync(model.SlugName, model.Id);

                                await surveyAnalysisService.MergeSurveyAnswerToAnalysisAsync(model.ToAnalysisServiceSurveyAnswer());
                            }

                            processItems.Clear();
                        }

                        await tx.CommitAsync();
                    }

                    await Task.Delay(TimeSpan.FromMilliseconds(delayMs), cancellationToken);
                }
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.ServiceRequestFailed(ex.ToString());
                throw;
            }
        }