public List <T> AddNew <T>(IEnumerable <T> dataset, DataProviderContext dataProviderContext) where T : class, IData { SqlDataTypeStore sqlDataTypeStore = TryGetsqlDataTypeStore(typeof(T)); if (sqlDataTypeStore == null) { throw new InvalidOperationException(string.Format("The interface '{0}' has not been configures", typeof(T).FullName)); } var resultDataset = new List <T>(); using (var dataContext = CreateDataContext()) { foreach (IData data in dataset) { Verify.ArgumentCondition(data != null, "dataset", "Data set may not contain nulls"); IData newData = sqlDataTypeStore.AddNew(data, dataProviderContext, dataContext); (newData as IEntity).Commit(); CheckConstraints(newData); resultDataset.Add((T)newData); } SubmitChanges(dataContext); } return(resultDataset); }
public override async Task <CreateVolumeResponse> CreateVolume( CreateVolumeRequest request, ServerCallContext context) { CreateVolumeResponse response = new CreateVolumeResponse(); if (string.IsNullOrEmpty(request.Name)) { logger.LogDebug("Validation fail"); throw new RpcException(new Status(StatusCode.InvalidArgument, "Name cannot be empty")); } using (var _s = logger.StepInformation("{0}, name: {1}", nameof(CreateVolume), request.Name)) { try { var ctx = new DataProviderContext <ManagedDiskConfig>(); await contextConfig.Provide(ctx); var actx = new AzureAuthConfigProviderContext { Secrets = request.ControllerCreateSecrets }; var provisionService = provisionServiceFactory.Create( provider.Provide(actx), ctx.Result.SubscriptionId); var sizeGiB = byteUnitConverter.ToGibibyte( request.CapacityRange == null ? 1 : request.CapacityRange.RequiredBytes); var md = await provisionService.CreateAsync( ctx.Result.SubscriptionId, ctx.Result.ResourceGroupName, request.Name, ctx.Result.Location, sizeGiB); response.Volume = new Volume { Id = md.Id.Id, CapacityBytes = byteUnitConverter.FromGigibyte(md.Size), }; } catch (Exception ex) { logger.LogError(ex, "Exception in CreateAsync"); throw new RpcException(new Status(StatusCode.Internal, ex.Message)); } _s.Commit(); } return(response); }
public IDataProvider GetDataProvider(DataProviderContext context) { switch (context) { case DataProviderWithMetaDataMultiRoiContext roiContext: return(new DataWithMetaDataMultiRoiProvider(roiContext)); case DataProviderWithMetaDataContext dataContext: return(new DataWithMetaDataSingleRoiProvider(dataContext)); case DataProviderWithoutMetaDataContext metaDataContext: return(new DataWithoutMetaDataProvider(metaDataContext)); } return(null); }
public void Delete(IEnumerable <DataSourceId> dataSourceIds, DataProviderContext dataProivderContext) { DataContext dataContext = null; try { foreach (DataSourceId dataSourceId in dataSourceIds) { if (dataSourceId == null) { throw new ArgumentException("dataSourceIds contains nulls"); } using (new DataScope(dataSourceId.DataScopeIdentifier, dataSourceId.LocaleScope)) { SqlDataTypeStore sqlDataTypeStore = TryGetsqlDataTypeStore(dataSourceId.InterfaceType); if (sqlDataTypeStore == null) { throw new InvalidOperationException(string.Format("The interface '{0}' has not been configures", dataSourceId.InterfaceType.FullName)); } IData data = sqlDataTypeStore.GetDataByDataId(dataSourceId.DataId, dataProivderContext); Verify.That(data != null, "Row has already been deleted"); if (dataContext == null) { dataContext = CreateDataContext(); } sqlDataTypeStore.RemoveData(data, dataContext); } } if (dataContext != null) { SubmitChanges(dataContext); } } finally { if (dataContext != null) { dataContext.Dispose(); } } }
public StaticFile(string fullPath, DataProviderContext context, string storeId, string providerRoot) { string websitePath = PathUtil.GetWebsitePath(fullPath); string providerRelativePath = websitePath.Substring(providerRoot.Length - 1); Id = CalculateId(providerRelativePath); DownloadUrl = websitePath; FileName = Path.GetFileName(providerRelativePath); FolderPath = Path.GetDirectoryName(providerRelativePath).Replace("\\", "/"); StoreId = storeId; DataSourceId = context.CreateDataSourceId(new MediaDataId { Id = this.Id, MediaType = MediaElementType.File }, typeof(IMediaFile)); CreationTime = DateTime.MinValue; LastWriteTime = DateTime.MinValue; Length = 0; }
public StaticFolder(string fullPath, DataProviderContext context, string storeId, string providerRoot) { string websitePath = PathUtil.GetWebsitePath(fullPath); string providerRelativePath = websitePath.Substring(providerRoot.Length - 1); Id = CalculateId(providerRelativePath); StoreId = storeId; DataSourceId = context.CreateDataSourceId(new MediaDataId { Id = this.Id, MediaType = MediaElementType.Folder }, typeof(IMediaFileFolder)); Description = ""; Title = System.IO.Path.GetFileName(providerRelativePath); StoreId = storeId; Path = providerRelativePath; KeyPath = storeId + ":" + Id; CompositePath = storeId + ":" + providerRelativePath; }
public override Task Provide(DataProviderContext <ManagedDiskConfig> context) { var subsId = Environment.GetEnvironmentVariable("DEFAULT_SUBSCRIPTION"); if (!string.IsNullOrEmpty(subsId)) { context.Result = new ManagedDiskConfig { SubscriptionId = subsId, ResourceGroupName = Environment.GetEnvironmentVariable("DEFAULT_RESOURCEGROUP"), Location = Environment.GetEnvironmentVariable("DEFAULT_LOCATION"), }; return(Task.CompletedTask); } if (Inner != null) { return(Inner.Provide(context)); } return(Task.CompletedTask); }
public override async Task Provide(DataProviderContext <ManagedDiskConfig> context) { var im = await instanceMetadataService.GetInstanceMetadataAsync(); if (im != null) { context.Result = new ManagedDiskConfig { SubscriptionId = im.Compute.SubscriptionId, ResourceGroupName = im.Compute.ResourceGroupName, Location = im.Compute.Location, }; return; } if (Inner != null) { await Inner.Provide(context); } }
protected virtual async Task <List <string> > GetTenantIdsAsync(string stamp, DateTime startTime, DateTime endTime, DataProviderContext dataProviderContext, PlatformType platformType) { var dp = new DataProviders.DataProviders(dataProviderContext); var tenantIds = new List <string>(); var kustoQuery = GetTenantIdQuery(stamp, startTime, endTime, platformType); var kustoTask = dp.Kusto.ExecuteQuery(kustoQuery, stamp, operationName: platformType == PlatformType.Windows ? KustoOperations.GetTenantIdForWindows : KustoOperations.GetTenantIdForLinux); tenantIds = GetTenantIdsFromTable(await kustoTask); return(tenantIds); }
protected override async Task <List <string> > GetTenantIdsAsync(string stamp, DateTime startTime, DateTime endTime, DataProviderContext dataProviderContext, PlatformType platformType) { if (platformType == PlatformType.Windows) { return(await base.GetTenantIdsAsync(stamp, startTime, endTime, dataProviderContext, platformType)); } else { return(await Task.FromResult(new List <string>())); } }
public async Task <Tuple <List <string>, PlatformType> > GetTenantIdForStamp(string stamp, bool isPublicStamp, DateTime startTime, DateTime endTime, DataProviderContext dataProviderContext) { var dp = new DataProviders.DataProviders(dataProviderContext); if (string.IsNullOrWhiteSpace(stamp)) { throw new ArgumentNullException("stamp"); } if (_tenantCache.TryGetValue(stamp.ToLower(), out Tuple <List <string>, PlatformType> result)) { return(result); } List <string> windowsTenantIds = new List <string>(); List <string> linuxTenantIds = new List <string>(); string windowsQuery = GetTenantIdQuery(stamp, startTime, endTime, PlatformType.Windows); string linuxQuery = GetTenantIdQuery(stamp, startTime, endTime, PlatformType.Linux); var windowsTask = dp.Kusto.ExecuteQuery(windowsQuery, stamp, operationName: KustoOperations.GetTenantIdForWindows); var linuxTask = dp.Kusto.ExecuteQuery(linuxQuery, stamp, operationName: KustoOperations.GetTenantIdForLinux); windowsTenantIds = GetTenantIdsFromTable(await windowsTask); linuxTenantIds = GetTenantIdsFromTable(await linuxTask); PlatformType type = PlatformType.Windows; List <string> tenantIds = windowsTenantIds.Union(linuxTenantIds).ToList(); if (windowsTenantIds.Any() && linuxTenantIds.Any()) { type = PlatformType.Windows | PlatformType.Linux; } else if (linuxTenantIds.Any()) { type = PlatformType.Linux; } result = new Tuple <List <string>, PlatformType>(tenantIds, type); // Only cache TenantIds if not empty if (tenantIds != null && tenantIds.Any()) { _tenantCache.TryAdd(stamp.ToLower(), result); } return(result); }
public async Task <StackType> GetApplicationStack(string subscriptionId, string resourceGroup, string siteName, DataProviderContext dataProviderContext) { var dp = new DataProviders.DataProviders(dataProviderContext); if (string.IsNullOrWhiteSpace(subscriptionId)) { throw new ArgumentNullException("subscriptionId"); } if (string.IsNullOrWhiteSpace(resourceGroup)) { throw new ArgumentNullException("resourceGroup"); } if (string.IsNullOrWhiteSpace(siteName)) { throw new ArgumentNullException("siteName"); } string queryTemplate = $@"WawsAn_dailyentity | where pdate >= ago(5d) and sitename =~ ""{siteName}"" and sitesubscription =~ ""{subscriptionId}"" and resourcegroup =~ ""{resourceGroup}"" | where sitestack !contains ""unknown"" and sitestack !contains ""no traffic"" and sitestack !contains ""undefined"" | top 1 by pdate desc | project sitestack"; DataTable stackTable = await dp.Kusto.ExecuteQuery(queryTemplate, DataProviderConstants.FakeStampForAnalyticsCluster, operationName : "GetApplicationStack"); if (stackTable == null || stackTable.Rows == null || stackTable.Rows.Count == 0) { return(StackType.None); } return(GetAppStackType(stackTable.Rows[0][0].ToString().ToLower())); }
public static ISupportObserverDataProvider GetDataProvider(OperationDataCache cache, DataSourcesConfiguration configuration, DataProviderContext dataProviderContext) { if (configuration.SupportObserverConfiguration.IsMockConfigured) { return(new MockSupportObserverDataProvider(cache, configuration.SupportObserverConfiguration, dataProviderContext)); } else { return(new SupportObserverDataProvider(cache, configuration.SupportObserverConfiguration, dataProviderContext)); } }
public async Task <Tuple <List <string>, PlatformType> > GetTenantIdForStamp(string stamp, bool isPublicStamp, DateTime startTime, DateTime endTime, DataProviderContext dataProviderContext) { if (string.IsNullOrWhiteSpace(stamp)) { throw new ArgumentNullException(nameof(stamp)); } var dp = new DataProviders.DataProviders(dataProviderContext); if (_tenantCache.TryGetValue(stamp.ToLower(), out Tuple <List <string>, PlatformType> result)) { return(result); } var windowsTenantIdsTask = GetTenantIdsAsync(stamp, startTime, endTime, dataProviderContext, PlatformType.Windows); var linuxTenantIdsTask = GetTenantIdsAsync(stamp, startTime, endTime, dataProviderContext, PlatformType.Linux); var windowsTenantIds = await windowsTenantIdsTask; var linuxTenantIds = await linuxTenantIdsTask; PlatformType type = PlatformType.Windows; List <string> tenantIds = windowsTenantIds.Union(linuxTenantIds).ToList(); if (windowsTenantIds.Any() && linuxTenantIds.Any()) { type = PlatformType.Windows | PlatformType.Linux; } else if (linuxTenantIds.Any()) { type = PlatformType.Linux; } result = new Tuple <List <string>, PlatformType>(tenantIds, type); // Only cache TenantIds if not empty and for Public Stamps if (tenantIds != null && tenantIds.Any() && isPublicStamp) { _tenantCache.TryAdd(stamp.ToLower(), result); } return(result); }
public IData AddNew(IData dataToAdd, DataProviderContext dataProivderContext, DataContext dataContext) { SqlDataTypeStoreTable storeTable = GetCurrentTable(); return(storeTable.SqlDataProviderHelper.AddData((ISqlDataContext)dataContext, dataToAdd, dataProivderContext)); }
public IData GetDataByDataId(IDataId dataId, DataProviderContext dataProivderContext) { SqlDataTypeStoreTable storage = GetCurrentTable(); return(storage.SqlDataProviderHelper.GetDataById(GetQueryable(), dataId, dataProivderContext)); }
public async Task <StackType> GetApplicationStack(string subscriptionId, string resourceGroup, string siteName, DataProviderContext dataProviderContext) { var dp = new DataProviders.DataProviders(dataProviderContext); if (string.IsNullOrWhiteSpace(subscriptionId)) { throw new ArgumentNullException("subscriptionId"); } if (string.IsNullOrWhiteSpace(resourceGroup)) { throw new ArgumentNullException("resourceGroup"); } if (string.IsNullOrWhiteSpace(siteName)) { throw new ArgumentNullException("siteName"); } string queryTemplate = $@"set query_results_cache_max_age = time(1d); WawsAn_dailyentity | where pdate >= ago(5d) and sitename =~ ""{siteName}"" and sitesubscription =~ ""{subscriptionId}"" and resourcegroup =~ ""{resourceGroup}"" | where sitestack !contains ""unknown"" and sitestack !contains ""no traffic"" and sitestack !contains ""undefined"" | top 1 by pdate desc | project sitestack"; DataTable stackTable = null; try { if (dataProviderContext.Configuration.KustoConfiguration.CloudDomain == DataProviderConstants.AzureCloud) { stackTable = await dp.Kusto.ExecuteQuery(queryTemplate, DataProviderConstants.FakeStampForAnalyticsCluster, operationName : "GetApplicationStack"); } } catch (Exception ex) { //swallow the exception. Since Mooncake does not have an analytics cluster DiagnosticsETWProvider.Instance.LogRuntimeHostHandledException(dataProviderContext.RequestId, "GetApplicationStack", subscriptionId, resourceGroup, siteName, ex.GetType().ToString(), ex.ToString()); } if (stackTable == null || stackTable.Rows == null || stackTable.Rows.Count == 0) { return(StackType.None); } return(GetAppStackType(stackTable.Rows[0][0].ToString().ToLower())); }