/// <summary>
 /// Stores the current selection of Reporting Level stats screen for the user.
 /// </summary>
 /// <param name="selectionCache">SelectionCache to store</param>
 public void StoreSelection(SelectionCache selectionCache)
 {
     if (selectionCache != null)
     {
         MemoryCache.Instance.Store(SelectionCacheToken, selectionCache);
     }
 }
        private void OnScriptsReloadBegin()
        {
            if (_selectionCache == null)
            {
                _selectionCache = new SelectionCache();
            }
            _selectionCache.Cache();

            // Clear references to the user scripts (we gonna reload an assembly)
            Editor.Instance.Scene.ClearRefsToSceneObjects(true);
        }
Exemplo n.º 3
0
        public async Task <SelectionCache> GetSelectionCache()
        {
            SelectionCache cache = await this._reportingLevelStatsService.RetrieveSelection();

            if (cache == null)
            {
                return(new SelectionCache());
            }

            return(cache);
        }
Exemplo n.º 4
0
        public PossibleSelections CollectFields(
            INamedOutputType type,
            SelectionSetNode selectionSet,
            Path path)
        {
            if (!_cache.TryGetValue(type, out SelectionCache? selectionCache))
            {
                selectionCache = new SelectionCache();
                _cache.Add(type, selectionCache);
            }

            if (!selectionCache.TryGetValue(
                    selectionSet,
                    out PossibleSelections? possibleSelections))
            {
                SelectionInfo returnType =
                    CollectFieldsInternal(type, selectionSet, path);

                if (type.IsAbstractType())
                {
                    var  list             = new List <SelectionInfo>();
                    bool singleModelShape = true;

                    foreach (ObjectType objectType in _schema.GetPossibleTypes(type))
                    {
                        SelectionInfo objectSelection =
                            CollectFieldsInternal(objectType, selectionSet, path);
                        list.Add(objectSelection);

                        if (!FieldSelectionsAreEqual(
                                returnType.Fields,
                                objectSelection.Fields))
                        {
                            singleModelShape = false;
                        }
                    }

                    if (!singleModelShape)
                    {
                        possibleSelections = new PossibleSelections(returnType, list);
                    }
                }

                if (possibleSelections is null)
                {
                    possibleSelections = new PossibleSelections(returnType);
                }

                selectionCache.Add(selectionSet, possibleSelections);
            }

            return(possibleSelections);
        }
Exemplo n.º 5
0
        public async Task <ReportingLevelEntity> GetReportingStats(bool ignoreCache = false)
        {
            ReportingLevelEntity entity;

            this._selectionCache = await this.GetSelectionCache();

            if (Resolver.Instance.Get <IConnectivityService>().HasConnection())
            {
                entity = await this._reportingLevelStatsService.RetrieveStats(this._selectionCache, ignoreCache);
            }
            else
            {
                entity = await this._reportingLevelStatsService.RetrieveStats(this._selectionCache);
            }

            if (entity == null || !entity.HasValidData)
            {
                if (entity == null)
                {
                    entity = new ReportingLevelEntity();
                }

                this.InvokeDataFetched(entity);
                return(entity);
            }

            this.UpdateSummary(entity.Sales);
            this.InvokeDataFetched(entity);

            this._currentEntity       = entity;
            this.Title                = entity.Name;
            this.LevelUpButtonEnabled = this._selectionCache.SelectedLevel != (int)SalesAreaHierarchy.Country;

            if (this._selectionCache.SelectedPeriod == null)
            {
                this._selectionCache.SelectedPeriod = this._reportingLevelStatsService.FirstPeriod(entity.ReportStats);
            }

            this.SelectedPeriod = this._selectionCache == null ? "-" : this._selectionCache.SelectedPeriod;
            var hasPrevious = this._reportingLevelStatsService.PreviousPeriod(entity.ReportStats, this.SelectedPeriod) != null;

            this.HasPrevious = hasPrevious;

            var selectedPeriod = this._selectionCache != null ? this._selectionCache.SelectedPeriod : string.Empty;
            var hasNext        = this._reportingLevelStatsService.NextPeriod(entity.ReportStats, selectedPeriod) != null;

            this.HasNext = hasNext;

            return(entity);
        }
        /// <summary>
        /// This method retrieves the ReportingLevel stats for a user, given a level and period
        /// </summary>
        /// <param name="selection">Selection of parameters</param>
        /// <param name="ignoreCache">If true, ignores any cached information (forced remote)</param>
        /// <returns>The reporting level stats for the give level and user</returns>
        public async Task <ReportingLevelEntity> RetrieveStats(SelectionCache selection, bool ignoreCache = false)
        {
            var cacheTokenItemId = selection.SelectedItemId;

            if (selection.SelectedLevel == SelectionCache.CountryLevel)
            {
                cacheTokenItemId = "country-level";
            }

            var cacheToken = string.Format(
                "{0}-{1}-{2}",
                cacheTokenItemId,
                selection.SelectedPeriodType,
                selection.SelectedLevel);

            // before using API, check the cache
            if (!ignoreCache)
            {
                var cachedResult = await MemoryCache.Instance.Get <ReportingLevelEntity>(cacheToken);

                // valid cache found, return that
                if (cachedResult != null)
                {
                    Logger.Debug("Return cached result.");
                    return(cachedResult);
                }
            }

            // if no connection do not try to continue with the API
            if (!this.connectivityService.HasConnection())
            {
                Logger.Error("No connection, unable to get stats.");
                return(new ReportingLevelEntity {
                    Status = ServiceReturnStatus.NoInternet
                });
            }

            Logger.Debug("No valid cache, get new stats.");
            var response = await this.api.FetchStats(selection.SelectedLevel, selection.SelectedItemId, selection.SelectedPeriodType);

            // if we have no response, return default
            if (response == null)
            {
                Logger.Error("Response == null, Server Error.");
                return(new ReportingLevelEntity {
                    Status = ServiceReturnStatus.ServerError
                });
            }

            // if the response was is not succesful, return default
            if (!response.IsSuccessStatus)
            {
                Logger.Error("API reports No Success, Server Error.");
                return(new ReportingLevelEntity {
                    Status = ServiceReturnStatus.ServerError
                });
            }

            // get the actual object from the response
            var result = response.GetObject();

            // if we do not have a response, return default object
            if (result == null)
            {
                Logger.Error("Unable to parse content from server, Parse Error.");
                return(new ReportingLevelEntity {
                    Status = ServiceReturnStatus.ParseError
                });
            }

            // seems all is ok
            result.Status = ServiceReturnStatus.Success;

            if (result.HasValidData)
            {
                await MemoryCache.Instance.Store(cacheToken, result);
            }

            // return the object, it is valid
            return(result);
        }
 public ReportStat[] Filter(ReportStat[] list, SelectionCache selectionCache)
 {
     return(list.Where(r => r.Date == selectionCache.SelectedPeriod).ToArray());
 }