public async Task <T> SaveToQueue <T>(T obj, VerifiedUserContext user, string resourceId) where T : IHSObject { try { var orch = new OrchestrationObject <T> { Token = user.AccessToken, ClientId = user.ClientID, ID = obj.ID, Model = obj }; await _blobQueue.Save(orch.BuildPath(resourceId, user.ClientID), JsonConvert.SerializeObject(orch)); return(await Task.FromResult(obj)); } catch (OrderCloudIntegrationException ex) { throw new OrderCloudIntegrationException(ex.ApiError); } catch (Exception ex) { await _log.Save(new OrchestrationLog() { Level = LogLevel.Error, Message = $"Failed to save blob to queue from API: {user.SupplierID} - {typeof(T)}: {ex.Message}", Current = JObject.FromObject(obj) }); throw new OrderCloudIntegrationException(Headstart.Models.ErrorCodes.All["WriteFailure"], obj); } }
public async Task Update() { var list = await GetRateList(); await Throttler.RunAsync(list.Items, 100, 10, async rate => { var rates = await Get(rate.Currency); await _blob.Save($"{rate.Currency}.json", JsonConvert.SerializeObject(rates)); }); }
public async Task <ImageAsset> CreateImage(AssetUpload asset) { var container = _blob.Container.Name; var assetGuid = Guid.NewGuid().ToString(); using (var image = Image.FromStream(asset.File.OpenReadStream())) { var small = image.ResizeSmallerDimensionToTarget(100); var medium = image.ResizeSmallerDimensionToTarget(300); await Task.WhenAll(new[] { _blob.Save(assetGuid, medium.ToBytes(ImageFormat.Png), "image/png"), _blob.Save($"{assetGuid}-s", small.ToBytes(ImageFormat.Png), "image/png") }); } return(new ImageAsset { Url = $"{GetBaseUrl()}{container}/{assetGuid}", ThumbnailUrl = $"{GetBaseUrl()}{container}/{assetGuid}-s" }); }
public async Task SaveToCache(WorkItem wi) { if (wi.Cache == null) { await Task.CompletedTask; } try { await _blobCache.Save($"{wi.ResourceId.ToLower()}/{wi.ClientId}/{wi.RecordType.ToString().ToLower()}/{wi.RecordId}", wi.Cache); } catch (Exception ex) { throw new OrchestrationException(OrchestrationErrorType.CacheUpdateError, wi, ex.Message); } }
public async Task <EnvironmentSeedResponse> Seed(EnvironmentSeed seed) { if (string.IsNullOrEmpty(_settings.OrderCloudSettings.ApiUrl)) { throw new Exception("Missing required app setting OrderCloudSettings:ApiUrl"); } if (string.IsNullOrEmpty(_settings.OrderCloudSettings.WebhookHashKey)) { throw new Exception("Missing required app setting OrderCloudSettings:WebhookHashKey"); } if (string.IsNullOrEmpty(_settings.EnvironmentSettings.MiddlewareBaseUrl)) { throw new Exception("Missing required app setting EnvironmentSettings:MiddlewareBaseUrl"); } var portalUserToken = await _portal.Login(seed.PortalUsername, seed.PortalPassword); await VerifyOrgExists(seed.SellerOrgID, portalUserToken); var orgToken = await _portal.GetOrgToken(seed.SellerOrgID, portalUserToken); await CreateDefaultSellerUsers(seed, orgToken); await CreateIncrementors(orgToken); // must be before CreateBuyers await CreateMessageSenders(seed, orgToken); // must be before CreateBuyers and CreateSuppliers await CreateSecurityProfiles(orgToken); await CreateBuyers(seed, orgToken); await CreateConfigureAnonBuyer(seed, orgToken); await CreateApiClients(orgToken); await AssignSecurityProfiles(seed, orgToken); var apiClients = await GetApiClients(orgToken); await CreateXPIndices(orgToken); await CreateAndAssignIntegrationEvents(new string[] { apiClients.BuyerUiApiClient.ID }, apiClients.BuyerLocalUiApiClient.ID, orgToken); await CreateSuppliers(seed, orgToken); // populates exchange rates into blob container name: settings.BlobSettings.ContainerNameExchangeRates or "currency" if setting is not defined await _exhangeRates.Update(); // populate default english translations into blob container name: settings.BlobSettings.ContainerNameTranslations or "ngx-translate" if setting is not defined // provide other language files to support multiple languages var currentDirectory = Directory.GetCurrentDirectory(); var englishTranslationsPath = Path.GetFullPath(Path.Combine(currentDirectory, @"..\Headstart.Common\Assets\english-translations.json")); await _translationsBlob.Save("i18n/en.json", File.ReadAllText(englishTranslationsPath)); return(new EnvironmentSeedResponse { Comments = "Success! Your environment is now seeded. The following clientIDs & secrets should be used to finalize the configuration of your application. The initial admin username and password can be used to sign into your admin application", ApiClients = new Dictionary <string, dynamic> { ["Middleware"] = new { ClientID = apiClients.MiddlewareApiClient.ID, ClientSecret = apiClients.MiddlewareApiClient.ClientSecret }, ["Seller"] = new { ClientID = apiClients.AdminUiApiClient.ID }, ["Buyer"] = new { ClientID = apiClients.BuyerUiApiClient.ID } } }); }