Exemplo n.º 1
0
        /// <summary>
        /// Gets the summary volumes parameters according to the calculation type
        /// </summary>
        /// <param name="projectUid">Project UID</param>
        /// <param name="volumeCalcType">The summary volumes calculation type</param>
        /// <param name="volumeBaseUid">Base Design or Filter UID for summary volumes determined by volumeCalcType</param>
        /// <param name="volumeTopUid">Top Design or Filter UID for summary volumes determined by volumeCalcType</param>
        /// <returns>Tuple of base filter, top filter and volume design descriptor</returns>
        public async Task <Tuple <FilterResult, FilterResult, DesignDescriptor> > GetSummaryVolumesParameters(
            Guid projectUid, VolumeCalcType?volumeCalcType, Guid?volumeBaseUid, Guid?volumeTopUid, string userUid,
            IHeaderDictionary customHeaders, string projectTimeZone)
        {
            Task <FilterResult>     baseFilter   = null;
            Task <FilterResult>     topFilter    = null;
            Task <DesignDescriptor> volumeDesign = null;

            if (volumeCalcType.HasValue)
            {
                switch (volumeCalcType.Value)
                {
                case VolumeCalcType.GroundToGround:
                    baseFilter = _filterUtilities.GetCompactionFilter(projectUid, projectTimeZone, userUid, volumeBaseUid, customHeaders);
                    topFilter  = _filterUtilities.GetCompactionFilter(projectUid, projectTimeZone, userUid, volumeTopUid, customHeaders);

                    await Task.WhenAll(baseFilter, topFilter);

                    break;

                case VolumeCalcType.GroundToDesign:
                    baseFilter   = _filterUtilities.GetCompactionFilter(projectUid, projectTimeZone, userUid, volumeBaseUid, customHeaders);
                    volumeDesign = _designUtilities.GetAndValidateDesignDescriptor(projectUid, volumeTopUid, userUid, customHeaders, OperationType.Profiling);

                    await Task.WhenAll(baseFilter, volumeDesign);

                    break;

                case VolumeCalcType.DesignToGround:
                    volumeDesign = _designUtilities.GetAndValidateDesignDescriptor(projectUid, volumeTopUid, userUid, customHeaders, OperationType.Profiling);
                    topFilter    = _filterUtilities.GetCompactionFilter(projectUid, projectTimeZone, userUid, volumeTopUid, customHeaders);

                    await Task.WhenAll(volumeDesign, topFilter);

                    break;
                }
            }

            return(new Tuple <FilterResult, FilterResult, DesignDescriptor>(baseFilter?.Result, topFilter?.Result, volumeDesign?.Result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of the <see cref="FilterResult"/> class and populates it with data from the <see cref="Filter"/> model class.
        /// </summary>
        public async Task <FilterResult> GetCompactionFilter(
            Guid projectUid, string projectTimeZone, string userUid, Guid?filterUid, IHeaderDictionary customHeaders,
            bool filterMustExist = false)
        {
            var filterKey = filterUid.HasValue ? $"{nameof(FilterResult)} {filterUid.Value}" : string.Empty;
            // Filter models are immutable except for their Name.
            // This service doesn't consider the Name in any of it's operations so we don't mind if our
            // cached object is out of date in this regard.
            var cachedFilter = filterUid.HasValue ? _filterCache.Get <FilterResult>(filterKey) : null;

            if (cachedFilter != null)
            {
                cachedFilter.ApplyDateRange(projectTimeZone, true);

                return(cachedFilter);
            }

            var excludedSs = await _designUtilities.GetExcludedSurveyedSurfaceIds(projectUid, userUid, customHeaders);

            var  excludedIds    = excludedSs?.Select(e => e.Item1).ToList();
            var  excludedUids   = excludedSs?.Select(e => e.Item2).ToList();
            bool haveExcludedSs = excludedSs != null && excludedSs.Count > 0;

            if (!filterUid.HasValue)
            {
                return(haveExcludedSs
          ? FilterResult.CreateFilter(excludedIds, excludedUids)
          : null);
            }

            try
            {
                DesignDescriptor designDescriptor    = null;
                DesignDescriptor alignmentDescriptor = null;

                var filterData = await GetFilterDescriptor(projectUid, filterUid.Value, customHeaders);

                if (filterMustExist && filterData == null)
                {
                    throw new ServiceException(HttpStatusCode.BadRequest,
                                               new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                           "Invalid Filter UID."));
                }

                if (filterData != null)
                {
                    _log.LogDebug($"Filter from Filter Svc: {JsonConvert.SerializeObject(filterData)}");
                    if (filterData.DesignUid != null && Guid.TryParse(filterData.DesignUid, out Guid designUidGuid))
                    {
                        designDescriptor = await _designUtilities.GetAndValidateDesignDescriptor(projectUid, designUidGuid, userUid, customHeaders);
                    }

                    if (filterData.AlignmentUid != null && Guid.TryParse(filterData.AlignmentUid, out Guid alignmentUidGuid))
                    {
                        alignmentDescriptor = await _designUtilities.GetAndValidateDesignDescriptor(projectUid, alignmentUidGuid, userUid, customHeaders);
                    }

                    if (filterData.HasData() || haveExcludedSs || designDescriptor != null)
                    {
                        filterData.ApplyDateRange(projectTimeZone, true);

                        var layerMethod = filterData.LayerNumber.HasValue
              ? FilterLayerMethod.TagfileLayerNumber
              : FilterLayerMethod.None;

                        bool?returnEarliest = null;
                        if (filterData.ElevationType == ElevationType.First)
                        {
                            returnEarliest = true;
                        }

                        var raptorFilter = new FilterResult(filterUid, filterData, filterData.PolygonLL, alignmentDescriptor, layerMethod, excludedIds, excludedUids, returnEarliest, designDescriptor);

                        _log.LogDebug($"Filter after filter conversion: {JsonConvert.SerializeObject(raptorFilter)}");

                        // The filter will be removed from memory and recalculated to ensure we have the latest filter on any relevant changes
                        var filterTags = new List <string>()
                        {
                            filterUid.Value.ToString(),
                            projectUid.ToString()
                        };

                        _filterCache.Set(filterKey, raptorFilter, filterTags, _filterCacheOptions);

                        return(raptorFilter);
                    }
                }
            }
            catch (ServiceException ex)
            {
                _log.LogDebug($"EXCEPTION caught - cannot find filter {ex.Message} {ex.GetContent} {ex.GetResult.Message}");
                throw;
            }
            catch (Exception ex)
            {
                _log.LogDebug("EXCEPTION caught - cannot find filter " + ex.Message);
                throw;
            }

            return(haveExcludedSs ? FilterResult.CreateFilter(excludedIds, excludedUids) : null);
        }