/// <summary> /// Retrieves data from WaterOneFlow services, persists a publicly-accessible copy as a CSV-formatted document /// (see <a href="http://www.ietf.org/rfc/rfc4180.txt">rfc-4180</a> and <a href="http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm">this discussion</a>), /// and returns a web-formatted response including a URI to the reference link. /// </summary> /// <param name="SeriesID"></param> /// <param name="lat"></param> /// <param name="lng"></param> /// <returns></returns> public async Task <SeriesData> Get(int SeriesID, double lat, double lng) { DateTimeOffset requestTime = DateTimeOffset.UtcNow; DataExportRequest cachedResult = await wdcStore.CheckIfSeriesExistsInStorage(CUAHSIDataStorage.LogHelper.GetCUAHSIDataStorage(), SeriesID, requestTime); if (cachedResult == null) { //get series from wateroneflow and return response Tuple <Stream, SeriesData> data = await discoveryService.GetSeriesDataObjectAndStreamFromSeriesTriple(SeriesID, lat, lng); string nameGuid = Guid.NewGuid().ToString(); var dl = wdcStore.PersistSeriesData(data.Item2, nameGuid, requestTime); //fire and forget => no reason to require consistency with user download. var persist = wdcStore.PersistSeriesDocumentStream(data.Item1, SeriesID, nameGuid, DateTime.UtcNow); await Task.WhenAll(new List <Task>() { dl, persist }); data.Item2.wdcCache = dl.Result.Uri; return(data.Item2); } else { //get series from cloud cache and return response ServerSideHydroDesktop.ObjectModel.Series dataResult = await wdcStore.GetWaterOneFlowFromCloudCache(SeriesID.ToString(), cachedResult.DownloadGuid, cachedResult.ServUrl); SeriesMetadata meta = await discoveryService.SeriesMetaDataOfSeriesID(SeriesID, lat, lng); IList <DataValue> dataValues = dataResult.DataValueList.OrderBy(a => a.DateTimeUTC).Select(aa => new DataValue(aa)).ToList(); return(new SeriesData(meta.SeriesID, meta, dataResult.QualityControlLevel.IsValid, dataValues, dataResult.Variable.VariableUnit.Name, dataResult.Variable.VariableUnit.Abbreviation, dataResult.Site.VerticalDatum, dataResult.Site.Elevation_m)); } // SeriesData data = await discoveryService.GetSeriesDataObjectFromSeriesTriple(SeriesID, lat, lng); }
public DataExporterContext(DataExportRequest request, bool isPreview, CancellationToken cancellationToken) { Request = request; IsPreview = isPreview; CancellationToken = cancellationToken; FolderContent = request.Profile.GetExportFolder(true, true); Filter = Deserialize <ExportFilter>(request.Profile.Filtering) ?? new(); Projection = Deserialize <ExportProjection>(request.Profile.Projection) ?? new(); if (request.Profile.Projection.IsEmpty()) { Projection.DescriptionMergingId = (int)ExportDescriptionMerging.Description; } Result = new DataExportResult { FileFolder = IsFileBasedExport ? FolderContent : null }; ExecuteContext = new ExportExecuteContext(Result, FolderContent, CancellationToken) { Filter = Filter, Projection = Projection, ProfileId = request.Profile.Id }; if (!IsPreview) { ExecuteContext.ProgressValueSetter = Request.ProgressValueSetter; } }
public async Task GetExportStatsReturnsBadRequestWhenRequestIsInvalid() { DataExportRequest request = new DataExportRequest(); _domainStatusController.ModelState.AddModelError("testKey", "testErrorMessage"); IActionResult result = await _domainStatusController.GetAggregateReportExport(request); Assert.That(result, Is.TypeOf <BadRequestObjectResult>()); }
public DataExporterContext( DataExportRequest request, CancellationToken cancellationToken, bool isPreview = false) { Request = request; CancellationToken = cancellationToken; Filter = XmlHelper.Deserialize <ExportFilter>(request.Profile.Filtering); Projection = XmlHelper.Deserialize <ExportProjection>(request.Profile.Projection); IsPreview = isPreview; if (request.Profile.Projection.IsEmpty()) { Projection.DescriptionMergingId = (int)ExportDescriptionMerging.Description; } FolderContent = request.Profile.GetExportFolder(true, true); DeliveryTimes = new Dictionary <int, DeliveryTime>(); QuantityUnits = new Dictionary <int, QuantityUnit>(); Stores = new Dictionary <int, Store>(); Languages = new Dictionary <int, Language>(); Countries = new Dictionary <int, Country>(); ProductTemplates = new Dictionary <int, string>(); CategoryTemplates = new Dictionary <int, string>(); NewsletterSubscriptions = new HashSet <string>(); Translations = new Dictionary <string, LocalizedPropertyCollection>(); TranslationsPerPage = new Dictionary <string, LocalizedPropertyCollection>(); UrlRecords = new Dictionary <string, UrlRecordCollection>(); UrlRecordsPerPage = new Dictionary <string, UrlRecordCollection>(); StatsPerStore = new Dictionary <int, RecordStats>(); EntityIdsLoaded = new List <int>(); EntityIdsPerSegment = new HashSet <int>(); Result = new DataExportResult { FileFolder = IsFileBasedExport ? FolderContent : null }; ExecuteContext = new ExportExecuteContext(Result, CancellationToken, FolderContent); ExecuteContext.Filter = Filter; ExecuteContext.Projection = Projection; ExecuteContext.ProfileId = request.Profile.Id; if (!IsPreview) { ExecuteContext.ProgressValueSetter = Request.ProgressValueSetter; } }
//public bool SendNotification(int id, bool hasNewData) //{ // var context = new ShopConnectorRequestContext() // { // ActionMethod = "Notification", // HttpMethod = "POST", // RequestContent = "{0}={1}".FormatInvariant(ShopConnectorCore.Xml.HasNewData, hasNewData.ToString()) // }; // bool success = SendRequest(context, id); // return success; //} //public void ProcessNotification() //{ // var request = HttpContext.Current.Request; // string publicKey = request.Headers[ShopConnectorCore.Header.PublicKey]; // var controllingData = ShopConnectorCaching.ControllingData(); // var connection = controllingData.Connections.FirstOrDefault(x => x.PublicKey == publicKey && !x.IsForExport); // if (connection != null) // { // controllingData.ConnectionsUpdated = true; // connection.HasNewData = request.Form[ShopConnectorCore.Xml.HasNewData].ToBool(); // } //} public DataExportResult Export(ShopConnectorExportContext context, CancellationToken token, string providerSystemName) { var provider = _exportProfileService.Value.LoadProvider(providerSystemName); var profile = _exportProfileService.Value.GetSystemExportProfile(providerSystemName); if (profile == null) { profile = _exportProfileService.Value.InsertExportProfile(provider, true); } if (context.Connection == null) { var controllingData = ConnectionCache.ControllingData(); var connection = controllingData.Connections.FirstOrDefault(x => x.PublicKey == context.PublicKey && x.IsForExport); context.Connection = _connectionRepository.GetById(connection.Id); } var limitedToStoreIds = context.Connection.LimitedToStoreIds.ToIntArray(); var domain = _shopConnectorSettings.EnableSkuMapping ? context.Connection.Url.ToDomain() : string.Empty; var request = new DataExportRequest(profile, provider); request.CustomData.Add(ShopConnectorCore.Header.PublicKey, context.PublicKey); request.CustomData.Add("CategoryIds", context.CategoryIds); request.CustomData.Add("StoreIds", limitedToStoreIds); request.CustomData.Add("Domain", domain); request.HasPermission = true; if (providerSystemName == ShopConnectorProductXmlExportProvider.SystemName) { var fetchFrom = context.Model.FetchFrom.ToDateTimeIso8601(); var limitedToManufacturerIds = context.Connection.LimitedToManufacturerIds.ToIntArray(); request.ProductQuery = GetProductQuery( limitedToManufacturerIds, limitedToStoreIds, context.Model.FilterManufacturerIds, context.Model.FilterCategoryId.ToInt(), fetchFrom); } var result = _dataExporter.Value.Export(request, token); return(result); }
public async Task <IActionResult> GetAggregateReportExport(DataExportRequest request) { if (!ModelState.IsValid) { return(BadRequest(new ErrorResponse(ModelState.Values))); } IEnumerable <AggregateReportExportStats> aggregateReportExportStats = await _aggregateReportService.GetAggregateReportExport(request.Domain, request.Provider, request.Ip, request.StartDate, request.EndDate, request.IncludeSubdomains); Response.Headers[HeaderNames.ContentDisposition] = request.CsvDownload ? $"attachment; filename=\"AggregateSummaryReportExport_{request.Domain}_{request.StartDate:yyyy-MM-dd}_{request.EndDate:yyyy-MM-dd}.csv\"" : request.JsonDownload ? $"attachment; filename=\"AggregateSummaryReportExport_{request.Domain}_{request.StartDate:yyyy-MM-dd}_{request.EndDate:yyyy-MM-dd}.json\"" : request.JsonRender ? "inline" : ""; return(Ok(aggregateReportExportStats)); }
public DataExporterContext( DataExportRequest request, CancellationToken cancellationToken, bool isPreview = false) { Request = request; CancellationToken = cancellationToken; Filter = XmlHelper.Deserialize <ExportFilter>(request.Profile.Filtering); Projection = XmlHelper.Deserialize <ExportProjection>(request.Profile.Projection); IsPreview = isPreview; FolderContent = request.Profile.GetExportFolder(true, true); Categories = new Dictionary <int, Category>(); CategoryPathes = new Dictionary <int, string>(); DeliveryTimes = new Dictionary <int, DeliveryTime>(); QuantityUnits = new Dictionary <int, QuantityUnit>(); Stores = new Dictionary <int, Store>(); Languages = new Dictionary <int, Language>(); Countries = new Dictionary <int, Country>(); ProductTemplates = new Dictionary <int, string>(); CategoryTemplates = new Dictionary <int, string>(); NewsletterSubscriptions = new HashSet <string>(); RecordsPerStore = new Dictionary <int, int>(); EntityIdsLoaded = new List <int>(); EntityIdsPerSegment = new List <int>(); Result = new DataExportResult { FileFolder = (IsFileBasedExport ? FolderContent : null) }; ExecuteContext = new ExportExecuteContext(Result, CancellationToken, FolderContent); ExecuteContext.Projection = XmlHelper.Deserialize <ExportProjection>(request.Profile.Projection); if (!IsPreview) { ExecuteContext.ProgressValueSetter = Request.ProgressValueSetter; } }
public async Task GetAggregateReportExportReturnsStatsFromService() { DataExportRequest request = new DataExportRequest { CsvDownload = true, IncludeSubdomains = true, StartDate = new DateTime(2020, 06, 24), EndDate = new DateTime(2020, 07, 21) }; AggregateReportExportStats[] reportExportStats = { new AggregateReportExportStats("2001-01-29T10:30:50", "", "", "", "", "", 0, "", "", "", "", "","","", "", 0, 0, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", "", 0, "", "", 0, 0, 0, 0, 0, 0, 0, 0) }; A.CallTo(() => _aggregateReportService.GetAggregateReportExport(A <string> ._, A <string> ._, A <string> ._, A <DateTime> ._, A <DateTime> ._, A <bool> ._)).Returns(reportExportStats); IActionResult result = await _domainStatusController.GetAggregateReportExport(request); Assert.That(result, Is.TypeOf <OkObjectResult>()); Assert.AreSame(((OkObjectResult)result).Value, reportExportStats); }
public void SendReportExecutionRequest(ReportDefinition selectedReport, string path, UnitOfWork uow) { var reportServiceDestination = "";// ConfigurationStatic.GetParameterValue("ReportingServerAddress", uow); if (string.IsNullOrEmpty(reportServiceDestination)) { throw new InvalidOperationException("Reporting Sevrer Address Not Found"); } var def = new DataExportRequest() { ReportDefinitionID = selectedReport.ID, Parameters = new List <QueryParameterHelper>() }; foreach (var parameter in selectedReport.QueryParametersCollection) { def.Parameters.Add(new QueryParameterHelper() { ParameterName = parameter.ParameterName, ParameterValue = parameter.ParameterValue.ToString() }); } var xml = FastExportingMethod.Serialize(def); var xmlBytes = Encoding.UTF8.GetBytes(xml); var base64Xml = Convert.ToBase64String(xmlBytes); var encodedBase64Xml = WebUtility.UrlEncode(base64Xml); var request = WebRequest.Create($"http://{reportServiceDestination}/?data={encodedBase64Xml}"); request.Timeout = 600000; var response = request.GetResponse(); using (var file = response.GetResponseStream()) using (var fileStream = new FileStream(path, FileMode.Create)) file?.CopyTo(fileStream); }
public async Task <IActionResult> PreviewList(GridCommand command, int id) { var(profile, provider) = await LoadProfileAndProvider(id); if (profile == null) { throw new ArgumentException($"Cannot find export profile with ID {id}."); } IGridModel gridModel = null; var request = new DataExportRequest(profile, provider); var previewResult = await _dataExporter.PreviewAsync(request, command.Page - 1, command.PageSize); var normalizedTotal = profile.Limit > 0 && previewResult.TotalRecords > profile.Limit ? profile.Limit : previewResult.TotalRecords; if (provider.Value.EntityType == ExportEntityType.Product) { var rows = previewResult.Data .Select(x => { var product = x.Entity as Product; return(new ExportPreviewProductModel { Id = product.Id, ProductTypeId = product.ProductTypeId, ProductTypeName = product.GetProductTypeLabel(Services.Localization), ProductTypeLabelHint = product.ProductTypeLabelHint, EditUrl = Url.Action("Edit", "Product", new { id = product.Id }), Name = x.Name, Sku = x.Sku, Price = x.Price, Published = product.Published, StockQuantity = product.StockQuantity, AdminComment = x.AdminComment }); }) .ToList(); gridModel = new GridModel <ExportPreviewProductModel> { Rows = rows, Total = normalizedTotal }; } else if (provider.Value.EntityType == ExportEntityType.Order) { var rows = previewResult.Data .Select(x => new ExportPreviewOrderModel { Id = x.Id, HasNewPaymentNotification = x.HasNewPaymentNotification, EditUrl = Url.Action("Edit", "Order", new { id = x.Id }), OrderNumber = x.OrderNumber, OrderStatus = x.OrderStatus, PaymentStatus = x.PaymentStatus, ShippingStatus = x.ShippingStatus, CustomerId = x.CustomerId, CreatedOn = Services.DateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc), OrderTotal = x.OrderTotal, StoreName = (string)x.Store.Name }) .ToList(); gridModel = new GridModel <ExportPreviewOrderModel> { Rows = rows, Total = normalizedTotal }; } else if (provider.Value.EntityType == ExportEntityType.Category) { var rows = await previewResult.Data .SelectAsync(async x => { var category = x.Entity as Category; return(new ExportPreviewCategoryModel { Id = category.Id, Breadcrumb = await _categoryService.GetCategoryPathAsync(category, aliasPattern: "({0})"), FullName = x.FullName, Alias = x.Alias, Published = category.Published, DisplayOrder = category.DisplayOrder, LimitedToStores = category.LimitedToStores }); }) .AsyncToList(); gridModel = new GridModel <ExportPreviewCategoryModel> { Rows = rows, Total = normalizedTotal }; } else if (provider.Value.EntityType == ExportEntityType.Manufacturer) { var rows = previewResult.Data .Select(x => new ExportPreviewManufacturerModel { Id = x.Id, Name = x.Name, Published = x.Published, DisplayOrder = x.DisplayOrder, LimitedToStores = x.LimitedToStores }) .ToList(); gridModel = new GridModel <ExportPreviewManufacturerModel> { Rows = rows, Total = normalizedTotal }; } else if (provider.Value.EntityType == ExportEntityType.Customer) { var rows = previewResult.Data .Select(x => { var customer = x.Entity as Customer; var customerRoles = x.CustomerRoles as List <dynamic>; var customerRolesString = string.Join(", ", customerRoles.Select(x => x.Name)); return(new ExportPreviewCustomerModel { Id = customer.Id, Active = customer.Active, CreatedOn = Services.DateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc), CustomerRoleNames = customerRolesString, Email = customer.Email, FullName = x._FullName, LastActivityDate = Services.DateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc), Username = customer.Username }); }) .ToList(); gridModel = new GridModel <ExportPreviewCustomerModel> { Rows = rows, Total = normalizedTotal }; } else if (provider.Value.EntityType == ExportEntityType.NewsLetterSubscription) { var rows = previewResult.Data .Select(x => { var subscription = x.Entity as NewsletterSubscription; return(new ExportPreviewNewsletterSubscriptionModel { Id = subscription.Id, Active = subscription.Active, CreatedOn = Services.DateTimeHelper.ConvertToUserTime(subscription.CreatedOnUtc, DateTimeKind.Utc), Email = subscription.Email, StoreName = (string)x.Store.Name }); }) .ToList(); gridModel = new GridModel <ExportPreviewNewsletterSubscriptionModel> { Rows = rows, Total = normalizedTotal }; } else if (provider.Value.EntityType == ExportEntityType.ShoppingCartItem) { var guest = T("Admin.Customers.Guest").Value; var cartTypeName = await Services.Localization.GetLocalizedEnumAsync(ShoppingCartType.ShoppingCart); var wishlistTypeName = await Services.Localization.GetLocalizedEnumAsync(ShoppingCartType.Wishlist); var rows = previewResult.Data .Select(item => { var cartItem = item.Entity as ShoppingCartItem; return(new ExportPreviewShoppingCartItemModel { Id = cartItem.Id, ShoppingCartTypeId = cartItem.ShoppingCartTypeId, ShoppingCartTypeName = cartItem.ShoppingCartType == ShoppingCartType.Wishlist ? wishlistTypeName : cartTypeName, CustomerId = cartItem.CustomerId, CustomerEmail = cartItem.Customer.IsGuest() ? guest : cartItem.Customer.Email, ProductTypeId = cartItem.Product.ProductTypeId, ProductTypeName = cartItem.Product.GetProductTypeLabel(Services.Localization), ProductTypeLabelHint = cartItem.Product.ProductTypeLabelHint, Name = cartItem.Product.Name, Sku = cartItem.Product.Sku, Price = cartItem.Product.Price, Published = cartItem.Product.Published, StockQuantity = cartItem.Product.StockQuantity, AdminComment = cartItem.Product.AdminComment, CreatedOn = Services.DateTimeHelper.ConvertToUserTime(cartItem.CreatedOnUtc, DateTimeKind.Utc), StoreName = (string)item.Store.Name }); }) .ToList(); gridModel = new GridModel <ExportPreviewShoppingCartItemModel> { Rows = rows, Total = normalizedTotal }; } return(Json(gridModel)); }