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; } } }
private static IContainer SetupContainer(IServiceCollection services) { ContainerBuilder builder = new ContainerBuilder(); var cloudStorageAccount = ServiceFabricConfiguration.GetCloudStorageAccount(); var cosmosAccount = ServiceFabricConfiguration.GetCloudCosmosAccount(); builder.Register(c => cloudStorageAccount).Named <CloudStorageAccount>("azure-storage"); builder.Register(c => cosmosAccount).Named <CloudStorageAccount>("cosmos-storage"); builder .RegisterGeneric(typeof(AzureBlobContainer <>)) .WithParameter( new ResolvedParameter( (p, c) => p.Name == "account", (p, c) => c.ResolveNamed <CloudStorageAccount>("azure-storage"))) .As(typeof(IAzureBlobContainer <>)); //builder.RegisterGeneric(typeof(AzureBlobContainer<>)) // .As(typeof(IAzureBlobContainer<>)); builder .RegisterGeneric(typeof(AzureTable <>)) .WithParameter( new ResolvedParameter( (p, c) => p.Name == "account", (p, c) => c.ResolveNamed <CloudStorageAccount>("cosmos-storage"))) .As(typeof(IAzureTable <>)); //builder.RegisterGeneric(typeof(AzureTable<>)) // .As(typeof(IAzureTable<>)); builder.Populate(services); return(builder.Build()); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. // Persist data protection keys in Redis var redisConnectionString = ServiceFabricConfiguration.GetConfigurationSettingValue("ConnectionStrings", "RedisCacheConnectionString", "YourRedisCacheConnectionString"); services.AddDataProtection() .PersistKeysToRedis(ConnectionMultiplexer.Connect(redisConnectionString), "DataProtection-Keys"); // Add Redis-based distributed cache services.AddSingleton <IDistributedCache>(serviceProvider => new RedisCache(new RedisCacheOptions { Configuration = redisConnectionString })); services.AddSession(); services.AddMvc(); // Add Autofac var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule <ContainerBootstrapperModule>(); containerBuilder.Populate(services); var container = containerBuilder.Build(); return(new AutofacServiceProvider(container)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IConnectionMultiplexer>(serviceImplemtation => { string cacheConnection = ServiceFabricConfiguration.GetConfigurationSettingValue("ConnectionStrings", "RedisCacheConnectionString", "YourRedisCacheConnectionString"); return(ConnectionMultiplexer.Connect(cacheConnection)); }); services.AddMvc(); }
private static void Main(string[] args) { using (var serviceFabricConfiguration = new ServiceFabricConfiguration()) { using (var system = ActorSystem.Create("SF", serviceFabricConfiguration.GetSeedNodeConfig("SF", 8080))) { Console.ReadLine(); } } }
public void FullConfiguration_SetCustomPackageNameAndSection_ProviderIsConfigured() { // Arrange var config = new ServiceFabricConfiguration { ConfigPackageName = "TestConfig", ConfigSectionName = "Toggles" }; // Act and Assert Should.NotThrow(() => ServiceFabricConfigProvider.Configure(config)); }
public override async Task ObserveAsync(CancellationToken token) { // If set, this observer will only run during the supplied interval. // See Settings.xml, CertificateObserverConfiguration section, RunInterval parameter for an example. // This observer is only useful if you enable the web api for producing // an html page with a bunch of information that's easy to read in one go. if (!ObserverManager.ObserverWebAppDeployed || (this.RunInterval > TimeSpan.MinValue && DateTime.Now.Subtract(this.LastRunDateTime) < this.RunInterval)) { return; } token.ThrowIfCancellationRequested(); try { ServiceFabricConfiguration config = ServiceFabricConfiguration.Instance; this.SFVersion = config.FabricVersion; this.SFBinRoot = config.FabricBinRoot; this.SFCompatibilityJsonPath = config.CompatibilityJsonPath; this.SFCodePath = config.FabricCodePath; this.SFDataRoot = config.FabricDataRoot; this.SFLogRoot = config.FabricLogRoot; this.SFRootDir = config.FabricRoot; this.SFEnableCircularTraceSession = config.EnableCircularTraceSession; this.SFVolumeDiskServiceEnabled = config.IsSFVolumeDiskServiceEnabled; this.unsupportedPreviewFeaturesEnabled = config.EnableUnsupportedPreviewFeatures; this.SFNodeLastBootTime = config.NodeLastBootUpTime; } catch (Exception e) when(e is ArgumentException || e is IOException) { this.HealthReporter.ReportFabricObserverServiceHealth( this.FabricServiceContext.ServiceName.OriginalString, this.ObserverName, HealthState.Warning, $"{this.NodeName} | Handled Exception, but failed to read registry value:\n{e}"); } catch (Exception e) { this.HealthReporter.ReportFabricObserverServiceHealth( this.FabricServiceContext.ServiceName.OriginalString, this.ObserverName, HealthState.Warning, $"this.NodeName | Unhandled Exception trying to read registry value:\n{e}"); throw; } token.ThrowIfCancellationRequested(); await this.ReportAsync(token).ConfigureAwait(true); this.LastRunDateTime = DateTime.Now; }
private static IContainer SetupContainer() { ContainerBuilder builder = new ContainerBuilder(); var cloudStorageAccount = ServiceFabricConfiguration.GetCloudStorageAccount(); builder.RegisterInstance(cloudStorageAccount); builder.RegisterGeneric(typeof(AzureBlobContainer <>)) .As(typeof(IAzureBlobContainer <>)); builder.Register(c => ServiceProxy.Create <ISurveyAnalysisService>(new Uri("fabric:/Tailspin.SurveyAnalysisService.Application/SurveyAnalysisService"))) .As <ISurveyAnalysisService>(); return(builder.Build()); }
private static IContainer SetupContainer() { ContainerBuilder builder = new ContainerBuilder(); var cloudStorageAccount = ServiceFabricConfiguration.GetCloudStorageAccount(); builder.RegisterInstance(cloudStorageAccount); builder.RegisterGeneric(typeof(AzureBlobContainer <>)) .As(typeof(IAzureBlobContainer <>)); builder.RegisterGeneric(typeof(AzureTable <>)) .As(typeof(IAzureTable <>)); return(builder.Build()); }
private static IContainer SetupContainer() { ContainerBuilder builder = new ContainerBuilder(); var cloudStorageAccount = ServiceFabricConfiguration.GetCloudStorageAccount(); builder.RegisterInstance(cloudStorageAccount); builder.RegisterGeneric(typeof(AzureBlobContainer <>)) .As(typeof(IAzureBlobContainer <>)); builder.Register(c => new Tailspin.SurveyAnalysisService.Client.SurveyAnalysisService()) .As <ISurveyAnalysisService>(); return(builder.Build()); }
public static IHtmlContent SurveyLink(this IHtmlHelper htmlHelper, string linkText, string tenant, string surveySlug) { var publicSurveysWebsiteUrl = ServiceFabricConfiguration.GetConfigurationSettingValue("Endpoints", "PublicSurveyWebsiteUrl", "http://127.0.0.1/"); var surveyLink = string.Format(CultureInfo.InvariantCulture, "{0}/survey/{1}/{2}", publicSurveysWebsiteUrl, tenant, surveySlug); var tagBuilder = new TagBuilder("a"); tagBuilder.InnerHtml.AppendHtml(!string.IsNullOrEmpty(linkText) ? WebUtility.HtmlEncode(linkText) : string.Empty); tagBuilder.MergeAttribute("href", surveyLink); tagBuilder.TagRenderMode = TagRenderMode.Normal; return(tagBuilder); }
public AnswerAnalysisService(StatelessServiceContext context) : base(context) { // The number of connections depends on the particular usage in each application ServicePointManager.DefaultConnectionLimit = 12; var account = ServiceFabricConfiguration.GetCloudStorageAccount(); // TODO: Initialize DI container here or somewhere else since for each instance this constructor is invoked var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule <ContainerBootstrapperModule>(); containerBuilder.RegisterInstance(account); _container = containerBuilder.Build(); _container.Resolve <ISurveyAnswerStore>().InitializeAsync().Wait(); _container.Resolve <ISurveyAnswersSummaryStore>().InitializeAsync().Wait(); _container.Resolve <ITenantStore>().InitializeAsync().Wait(); _container.Resolve <ISurveyStore>().InitializeAsync().Wait(); _container.Resolve <ISurveyTransferStore>().InitializeAsync().Wait(); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. // Persist data protection keys in Redis var redisConnectionString = ServiceFabricConfiguration.GetConfigurationSettingValue("ConnectionStrings", "RedisCacheConnectionString", "YourRedisCacheConnectionString"); services.AddDataProtection() .PersistKeysToRedis(ConnectionMultiplexer.Connect(redisConnectionString), "DataProtection-Keys"); // Add Redis-based distributed cache services.AddSingleton <IDistributedCache>(serviceProvider => new RedisCache(new RedisCacheOptions { Configuration = redisConnectionString })); services.AddSession(); services.AddMvc(); var account = ServiceFabricConfiguration.GetCloudStorageAccount(); // Add Autofac var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule <ContainerBootstrapperModule>(); containerBuilder.Populate(services); containerBuilder.RegisterInstance(account); var container = containerBuilder.Build(); container.Resolve <ISurveyStore>().InitializeAsync().Wait(); container.Resolve <ISurveyAnswerStore>().InitializeAsync().Wait(); container.Resolve <ISurveyAnswersSummaryStore>().InitializeAsync().Wait(); container.Resolve <ISurveyTransferStore>().InitializeAsync().Wait(); container.Resolve <ITenantStore>().InitializeAsync().Wait(); return(new AutofacServiceProvider(container)); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. // Persist data protection keys in Redis var redisConnectionString = ServiceFabricConfiguration.GetConfigurationSettingValue("ConnectionStrings", "RedisCacheConnectionString", "YourRedisCacheConnectionString"); services.AddDataProtection() .PersistKeysToRedis(ConnectionMultiplexer.Connect(redisConnectionString), "DataProtection-Keys"); services.AddMvc(); var account = ServiceFabricConfiguration.GetCloudStorageAccount(); // Add Autofac var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule <ContainerBootstrapperModule>(); containerBuilder.Populate(services); containerBuilder.RegisterInstance(account); var container = containerBuilder.Build(); return(new AutofacServiceProvider(container)); }
private void WhenIGet() { _config = new ServiceFabricConfiguration(_host, _port, _serviceName); _provider = new ServiceFabricServiceDiscoveryProvider(_config); _services = _provider.Get().GetAwaiter().GetResult(); }
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; } }
public ServiceFabricServiceDiscoveryProvider(ServiceFabricConfiguration configuration) { _configuration = configuration; }