/// <summary> /// Initializes a new instance of the <see cref="FeedlyClient"/> class. /// </summary> /// <param name="environment">The environment of feedly.</param> /// <param name="clientId">The client id.</param> /// <param name="clientSecret">The client secret.</param> /// <param name="redirectUri">The redirect URI.</param> /// <exception cref="System.ArgumentNullException">redirectUri;Authentication and token generation requires an URI to redirect to afterwards</exception> public FeedlyClient(CloudEnvironment environment, string clientId, string clientSecret, string redirectUri) { if (String.IsNullOrEmpty(redirectUri)) { throw new ArgumentNullException("redirectUri", "Authentication and token generation requires an URI to redirect to afterwards"); } Environment = environment; ClientId = clientId; ClientSecret = clientSecret; RedirectUri = redirectUri; Client = new FeedlyHttpClient(new Uri(CloudUri, UriKind.Absolute)); }
public async Task <IActionResult> CreateOrUpdateEnvironment([FromForm] CloudEnvironment record) { var currentUser = await TryGetUser(User); record.OwnerAccountId = currentUser.Id; if (record.Id != 0) { await _dataAccess.UpdateEnvironment(record); return(Ok(new { record.Id })); } var environmentId = await _dataAccess.CreateEnvironment(record); return(Ok(new { environmentId })); }
public void TestOverflownMessages() { // Arrange var client = new CloudEnvironment(); var queue = client.QueueClient.GetQueueReference("test4"); var overflow = client.BlobClient.GetContainerReference("overflownqueues-4"); var result = string.Empty; var rnd = new Random(); var expected = new string(Enumerable.Range(1, 128 * 1024).Select(r => (char)rnd.Next(1024, 4096)).ToArray()); var sw = new Stopwatch(); var factory = new AzureExtendedQueueFactory(new AzureBlobContainer(overflow), new ConsoleLogService()); var equeue = factory.Create(new AzureQueue(queue)); using (var mre = new ManualResetEvent(false)) { var options = new HandleMessagesSerialOptions( TimeSpan.FromSeconds(0), TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(30), 5, new CancellationToken(), message => { result = message.GetMessageContents <string>(); mre.Set(); return(Task.FromResult(true)); }, null, ex => { throw ex; }); // Act sw.Start(); queue.CreateIfNotExists(); overflow.CreateIfNotExists(); queue.Clear(); equeue.AddMessageEntity(expected); equeue.HandleMessagesInSerialAsync(options); // Assert mre.WaitOne(); sw.Stop(); Trace.WriteLine("Total execution time (in seconds): " + sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual(expected, result); } }
public void TestReacquireLock() { // Arrange var client = new CloudEnvironment(); var consoleLog = new ConsoleLogService(); var lockProvider = new AzureLockStateProvider(consoleLog); var factory = new AzureGlobalMutexFactory((AzureBlobContainer)client.BlobClient.GetContainerReference("globalmutextests8"), lockProvider, consoleLog); // Act client.BreakAnyLeases("globalmutextests8", "test_lock"); var globalMutex = factory.CreateLock("test_lock"); var lease = globalMutex.CurrentLeaseId; globalMutex.LockAsync("test_lock").Wait(); // Assert Assert.IsTrue(globalMutex.CurrentLeaseId == lease); }
public void TestLock_Lock_LockIsReleased() { // Arrange var client = new CloudEnvironment(); var result = string.Empty; var consoleLog = new ConsoleLogService(); var lockProvider = new AzureLockStateProvider(consoleLog); var factory = new AzureGlobalMutexFactory((AzureBlobContainer)client.BlobClient.GetContainerReference("globalmutextests3"), lockProvider, consoleLog); // Act client.BreakAnyLeases("globalmutextests3", "test_lock"); using (var globalMutex = factory.CreateLock("test_lock")) result += "1"; using (var globalMutex = factory.CreateLock("test_lock")) result += "2"; // Assert Assert.AreEqual("12", result); }
public void TestTryLock_TryLock_Concurrency() { // Arrange var client = new CloudEnvironment(); var consoleLog = new ConsoleLogService(); var lockProvider = new AzureLockStateProvider(consoleLog); var factory = new AzureGlobalMutexFactory((AzureBlobContainer)client.BlobClient.GetContainerReference("globalmutextests2"), lockProvider, consoleLog); var result = string.Empty; var thread1 = new Thread( () => { bool isLocked; using (var globalMutex = factory.TryCreateLock("test_lock", out isLocked)) { if (isLocked) { result += "1"; } Thread.Sleep(2000); } }); var thread2 = new Thread( () => { Thread.Sleep(1000); // Ensure it will enter later than the previous method bool isLocked; using (var globalMutex = factory.TryCreateLock("test_lock", out isLocked)) if (isLocked) { result += "2"; } }); // Act client.BreakAnyLeases("globalmutextests2", "test_lock"); thread2.Start(); thread1.Start(); thread1.Join(); thread2.Join(); // Assert Assert.AreEqual("1", result); }
private void StartDiagnosticMonitor() { if (CloudEnvironment.IsAvailable) { using (CloudEnvironment.EnsureSafeHttpContext()) { var storageAccount = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingStorageAccount]; var storageKey = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingStorageAccountKey]; var diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration(); var diagnosticStorage = new CloudStorageAccount(new StorageCredentialsAccountAndKey(storageAccount, storageKey), true); // Configure the scheduled transfer period for all logs. diagnosticConfig.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1); diagnosticConfig.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(10); // Configure the logs levels for scheduled transfers. diagnosticConfig.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Error; diagnosticConfig.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined; this.diagnosticMonitor = DiagnosticMonitor.Start(diagnosticStorage, diagnosticConfig); } } }
public void TestSerial_ParallelProcessing() { // Arrange const int runCount = 100; var client = new CloudEnvironment(); var queue = client.QueueClient.GetQueueReference("test2"); var overflow = client.BlobClient.GetContainerReference("overflownqueues-2"); var locking = new object(); var result = string.Empty; var expected = string.Empty; var sw = new Stopwatch(); long actuallyRun = 0; var factory = new AzureExtendedQueueFactory(new AzureBlobContainer(overflow), new ConsoleLogService()); var equeue = factory.Create(new AzureQueue(queue)); var lck = new AsyncLock(); for (var i = 1; i < runCount + 1; i++) { expected += ((char)(i)).ToString(CultureInfo.InvariantCulture); } using (var mre = new ManualResetEvent(false)) { var options = new HandleMessagesParallelOptions( TimeSpan.FromSeconds(0), TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(30), 5, 50, new CancellationToken(), async message => { Trace.WriteLine(equeue.Statistics); using (await lck.LockAsync()) { var character = await message.GetMessageContentsAsync <string>().ConfigureAwait(false); result += character; } if (Interlocked.Increment(ref actuallyRun) == runCount) { mre.Set(); } return(true); }, null, ex => { throw ex; }); // Act sw.Start(); queue.CreateIfNotExists(); overflow.CreateIfNotExists(); queue.Clear(); for (var i = 1; i < runCount + 1; i++) { equeue.AddMessageEntity(((char)(i)).ToString(CultureInfo.InvariantCulture)); } equeue.HandleMessagesInParallelAsync(options); // Assert mre.WaitOne(); sw.Stop(); Trace.WriteLine("Total execution time (in seconds): " + sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture)); Assert.IsTrue(expected.All(c => result.Contains(c))); } }
static KeyVaultRepositoryFactory() { Environment = CloudEnvironment.AzureCommercial; }
private string GetCloudUri(CloudEnvironment environment) { return(String.Format("https://{0}.feedly.com", environment == CloudEnvironment.Production ? "cloud" : "sandbox")); }
public async Task <(bool isValid, string message)> TrySaveCredentials( CloudEnvironment cloudEnvironment, string tenantId, string clientId, string clientSecret, bool isEditing) { IEnumerable <AzureAccount> accounts = await this.appSettings .GetCloudAccounts <AzureAccount>(CloudAccountType.Azure); if (!isEditing && accounts.Any(a => a.TenantId == tenantId)) { // Ensuring not adding duplicate accounts, based upon TenantId. return(false, AppResources.AzureAccountManager_TryAddCredentials_DuplicateTenantId); } try { IAzure azure = AzureAccountManager.CreateAuthenticatedClient(cloudEnvironment.Id, tenantId, clientId, clientSecret); string subscriptionName = azure.GetCurrentSubscription().DisplayName; await this.appSettings.AddOrUpdateCloudAccount(new AzureAccount( subscriptionName, cloudEnvironment.Id, tenantId, clientId, clientSecret)); } catch (AdalServiceException e) when(e.ServiceErrorCodes != null && e.ServiceErrorCodes.Contains(AzureAccountManager.AdalInvalidClientIdServiceErrorCode)) { // AADSTS70001 - Invalid client ID. return(false, AppResources.AzureAccountManager_TryAddCredentials_InvalidClientId); } catch (AdalServiceException e) when(e.ServiceErrorCodes != null && e.ServiceErrorCodes.Contains(AzureAccountManager.AdalInvalidClientSecretServiceErrorCode)) { // AADSTS70002 - Invalid client secret. return(false, AppResources.AzureAccountManager_TryAddCredentials_InvalidClientSecret); } catch (AdalServiceException e) when(e.ServiceErrorCodes != null && e.ServiceErrorCodes.Contains(AzureAccountManager.AdalTenantDoesntExistServiceErrorCode)) { // AADSTS90002 - Tenant doesn't exist. return(false, AppResources.AzureAccountManager_TryAddCredentials_InvalidTenantId); } catch (AdalServiceException e) when(e.StatusCode == AzureAccountManager.AdalRequestTimeoutStatusCode) { // No internet return(false, AppResources.AzureAccountManager_TryAddCredentials_NoInternet); } catch (HttpRequestException e) when(e.InnerException is WebException web && web.Status == WebExceptionStatus.NameResolutionFailure) { // No internet return(false, AppResources.AzureAccountManager_TryAddCredentials_NoInternet); } return(true, string.Empty); }
private static void SetCloudEnvironment(CloudEnvironment infoCloudEnvironment) { PlayerPrefs.SetString(SettingsKeys.CloudEnvironment, infoCloudEnvironment.ToString()); }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { IRoleConfigurationSettingsExtension roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); if (roleConfigExtension != null && CloudEnvironment.IsAvailable) { ApplicationDiagnosticSettings diagnosticSettings = roleConfigExtension.GetSection <ApplicationDiagnosticSettings>(ApplicationDiagnosticSettings.SectionName); StorageAccountConfigurationSettings storageSettings = roleConfigExtension.GetSection <StorageAccountConfigurationSettings>(StorageAccountConfigurationSettings.SectionName); if (diagnosticSettings != null) { if (diagnosticSettings.DiagnosticEnabled) { DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration(); // Configure the scheduled transfer period for all logs. diagnosticConfig.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = diagnosticSettings.DiagnosticLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.Directories.ScheduledTransferPeriod = diagnosticSettings.FileLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.Logs.ScheduledTransferPeriod = diagnosticSettings.TraceLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.PerformanceCounters.ScheduledTransferPeriod = diagnosticSettings.PerformanceCountersTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.WindowsEventLog.ScheduledTransferPeriod = diagnosticSettings.EventLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); // Configure the logs levels for scheduled transfers. diagnosticConfig.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = FromTraceSourceLevel(diagnosticSettings.DiagnosticLogsTransferFilter); diagnosticConfig.Logs.ScheduledTransferLogLevelFilter = FromTraceSourceLevel(diagnosticSettings.TraceLogsTransferFilter); diagnosticConfig.WindowsEventLog.ScheduledTransferLogLevelFilter = FromTraceSourceLevel(diagnosticSettings.EventLogsTransferFilter); // Configure the Windows Event Log data sources. foreach (string logName in diagnosticSettings.EventLogDataSources.AllKeys) { diagnosticConfig.WindowsEventLog.DataSources.Add(logName); } // Configure the data sources for file-based logs. foreach (string containerName in diagnosticSettings.FileLogDirectories.AllKeys) { diagnosticConfig.Directories.DataSources.Add(new DirectoryConfiguration() { Container = containerName, Path = diagnosticSettings.FileLogDirectories[containerName].Value }); } // Configure the data sources for performance counter data foreach (string counterName in diagnosticSettings.PerformanceCountersDataSources.AllKeys) { diagnosticConfig.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration() { CounterSpecifier = counterName, SampleRate = TimeSpan.Parse(diagnosticSettings.PerformanceCountersDataSources[counterName].Value) }); } // Configure crash dumps collection. if (diagnosticSettings.CrashDumpCollectionEnabled) { CrashDumps.EnableCollection(true); } // Look up for the storage account definition. StorageAccountInfo storageAccountInfo = storageSettings.Accounts.Get(diagnosticSettings.DiagnosticStorageAccount); if (storageAccountInfo != null) { CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentialsAccountAndKey(storageAccountInfo.AccountName, storageAccountInfo.AccountKey), true); RetryPolicy retryPolicy = roleConfigExtension.StorageRetryPolicy; // Start the Azure Diagnostic Monitor using a retryable scope. this.diagnosticMonitor = retryPolicy.ExecuteAction <DiagnosticMonitor>(() => { return(DiagnosticMonitor.Start(storageAccount, diagnosticConfig)); }); } } else { // Do not proceed any further since diagnostic is not enabled in the application configuration. return; } } } if (null == this.diagnosticMonitor) { // Configuration extension is not available by some reasons, let try and see if DiagnosticsConnectionString property is set in the configuration. string diagConnectionString = CloudEnvironment.GetConfigurationSettingValue(Resources.DiagnosticsConnectionStringSettingName); // If DiagnosticsConnectionString is defined, start a Diagnostic Monitor using the storage account configuration specified in the setting. if (!String.IsNullOrEmpty(diagConnectionString)) { this.diagnosticMonitor = DiagnosticMonitor.Start(diagConnectionString, GetDiagnosticMonitorDefaultConfiguration()); } } }
public void TestSerial_BatchProcessingDelayed() { // Arrange const int runCount = 30; var client = new CloudEnvironment(); var queue = client.QueueClient.GetQueueReference("test12"); var overflow = client.BlobClient.GetContainerReference("overflownqueues-12"); var locking = new object(); var result = string.Empty; var expected = string.Empty; var sw = new Stopwatch(); var factory = new AzureExtendedQueueFactory(new AzureBlobContainer(overflow), new ConsoleLogService()); var equeue = factory.Create(new AzureQueue(queue)); var lck = new AsyncLock(); for (var i = 1; i < runCount + 1; i++) { expected += ((char)(i)).ToString(CultureInfo.InvariantCulture); } using (var mre = new ManualResetEvent(false)) { var options = new HandleMessagesBatchOptions( TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30), 5, 10, new CancellationToken(), async messages => { using (await lck.LockAsync()) { foreach (var message in messages) { var character = message.GetMessageContents <string>(); result += character; var innersw = new Stopwatch(); innersw.Start(); // Intentional spinning while (true) { if (innersw.Elapsed > TimeSpan.FromSeconds(5)) { break; } } } } if (result.Length == runCount) { mre.Set(); } return(messages); }, null, ex => { throw ex; }); // Act sw.Start(); queue.CreateIfNotExists(); overflow.CreateIfNotExists(); queue.Clear(); for (var i = 1; i < runCount + 1; i++) { equeue.AddMessageEntity(((char)(i)).ToString(CultureInfo.InvariantCulture)); } equeue.HandleMessagesInBatchAsync(options); // Assert mre.WaitOne(); sw.Stop(); Trace.WriteLine("Total execution time (in seconds): " + sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture)); Assert.IsTrue(expected.All(c => result.Contains(c))); } }
private string GetCloudUri(CloudEnvironment environment) { return String.Format("https://{0}.feedly.com", environment == CloudEnvironment.Production ? "cloud" : "sandbox"); }
public void TestErrorDuringRetrieval_Serialize() { // Arrange var client = new CloudEnvironment(); var queue = client.QueueClient.GetQueueReference("test9"); var overflow = client.BlobClient.GetContainerReference("overflownqueues-9"); var rnd = new Random(); ComplexModel result = null; var expected = new ComplexModel { Name = new string(Enumerable.Range(1, 128 * 1024).Select(r => (char)rnd.Next(1024, 4096)).ToArray()) }; var sw = new Stopwatch(); var succeeded = false; var factoryOne = new DefaultExtendedQueueFactory( new AzureQueueMessageProvider(), new AzureMaximumMessageSizeProvider(), new AzureMaximumMessagesPerRequestProvider(), new ChaosMonkeyOverflownMessageHandler(new AzureBlobContainer(overflow), ChaosMonkeyOverflownMessageHandler.FailureMode.Serialize), new ConsoleLogService() ); new AzureExtendedQueueFactory(new AzureBlobContainer(overflow), new ConsoleLogService()); var equeue = factoryOne.Create(new AzureQueue(queue)); using (var mre = new ManualResetEvent(false)) { var options = new HandleMessagesSerialOptions( TimeSpan.FromSeconds(0), TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(30), 5, new CancellationToken(), message => { result = message.GetMessageContents <ComplexModel>(); mre.Set(); return(Task.FromResult(true)); }, null, null); // Act sw.Start(); queue.CreateIfNotExists(); overflow.CreateIfNotExists(); queue.Clear(); try { equeue.AddMessageEntity(expected); } catch (Exception) { succeeded = true; } equeue.HandleMessagesInSerialAsync(options); // Assert sw.Stop(); Trace.WriteLine("Total execution time (in seconds): " + sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture)); Assert.IsTrue(succeeded); } }
public void TestLock_Lock_ManyLocks() { // Arrange var client = new CloudEnvironment(); var result = string.Empty; var consoleLog = new ConsoleLogService(); var lockProvider = new AzureLockStateProvider(consoleLog); var factory = new AzureGlobalMutexFactory((AzureBlobContainer)client.BlobClient.GetContainerReference("globalmutextests11"), lockProvider, consoleLog); var thread1 = new Thread( () => { using (var globalMutex = factory.CreateLock("test_lock")) { result += "1"; Trace.WriteLine("Thread 1 will sleep for 90 seconds"); Thread.Sleep(TimeSpan.FromSeconds(90)); Trace.WriteLine("Thread 1 woke up"); } }); var thread2 = new Thread( () => { Thread.Sleep(2000); // Ensure it will enter later than the previous method using (var globalMutex = factory.CreateLock("test_lock")) result += "2"; }); var thread3 = new Thread( () => { Thread.Sleep(2000); // Ensure it will enter later than the previous method using (var globalMutex = factory.CreateLock("test_lock")) result += "3"; }); var thread4 = new Thread( () => { Thread.Sleep(2000); // Ensure it will enter later than the previous method using (var globalMutex = factory.CreateLock("test_lock")) result += "4"; }); var thread5 = new Thread( () => { Thread.Sleep(2000); // Ensure it will enter later than the previous method using (var globalMutex = factory.CreateLock("test_lock")) result += "5"; }); var thread6 = new Thread( () => { Thread.Sleep(1000); // Ensure it will enter later than the previous method using (var globalMutex = factory.CreateLock("test_lock")) result += "6"; }); // Act client.BreakAnyLeases("globalmutextests1", "test_lock"); thread6.Start(); thread5.Start(); thread4.Start(); thread3.Start(); thread2.Start(); thread1.Start(); thread1.Join(); thread2.Join(); thread3.Join(); thread4.Join(); thread5.Join(); thread6.Join(); // Assert Trace.WriteLine(result); Assert.IsTrue(result.StartsWith("1")); Assert.IsTrue(result.Contains("2")); Assert.IsTrue(result.Contains("3")); Assert.IsTrue(result.Contains("4")); Assert.IsTrue(result.Contains("5")); Assert.IsTrue(result.Contains("6")); }
public void TestSerial_FauledNormalProcessing() { // Arrange const int runCount = 10; var client = new CloudEnvironment(); var overflow = client.BlobClient.GetContainerReference("overflownqueues-1"); var queue = client.QueueClient.GetQueueReference("test1"); var result = string.Empty; var expected = string.Empty; var sw = new Stopwatch(); var factory = new AzureExtendedQueueFactory(new AzureBlobContainer(overflow), new ConsoleLogService()); var equeue = factory.Create(new AzureQueue(queue)); for (var i = 0; i < runCount; i++) { if (i != 5) { expected += i.ToString(CultureInfo.InvariantCulture); } } using (var mre = new ManualResetEvent(false)) { var options = new HandleMessagesSerialOptions( TimeSpan.FromSeconds(0), TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(30), 5, new CancellationToken(), message => { if (message.GetMessageContents <string>() == "5") { throw new DivideByZeroException("Example Exception"); } if (message.GetMessageContents <string>() == "END") { mre.Set(); return(Task.FromResult(true)); } result += message.GetMessageContents <string>(); return(Task.FromResult(true)); }, null, ex => { throw ex; }); // Act sw.Start(); queue.CreateIfNotExists(); overflow.CreateIfNotExists(); queue.Clear(); for (var i = 0; i < runCount; i++) { equeue.AddMessageEntity(i.ToString(CultureInfo.InvariantCulture)); } equeue.AddMessageEntity("END"); equeue.HandleMessagesInSerialAsync(options); // Assert mre.WaitOne(); sw.Stop(); Trace.WriteLine("Total execution time (in seconds): " + sw.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture)); Trace.WriteLine(equeue.Statistics); Assert.AreEqual(expected, result); } }
private string GetCloudUri(CloudEnvironment environment) { return($"https://{(environment == CloudEnvironment.Production ? "cloud" : "sandbox")}.feedly.com"); }